Skip to content

Commit

Permalink
Adding label/description to BlockEditor/DuotoneControl (#54473)
Browse files Browse the repository at this point in the history
Adding label/description to `BlockEditor/DuotoneControl`
  • Loading branch information
Andrew Hayward authored Sep 28, 2023
1 parent 429e645 commit 15c2dd9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
16 changes: 14 additions & 2 deletions packages/block-editor/src/components/duotone-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import {
import { __ } from '@wordpress/i18n';
import { DOWN } from '@wordpress/keycodes';
import { Icon, filter } from '@wordpress/icons';
import { useInstanceId } from '@wordpress/compose';

function DuotoneControl( {
id: idProp,
colorPalette,
duotonePalette,
disableCustomColors,
Expand All @@ -31,6 +33,11 @@ function DuotoneControl( {
} else {
toolbarIcon = <Icon icon={ filter } />;
}

const actionLabel = __( 'Apply duotone filter' );
const id = useInstanceId( DuotoneControl, 'duotone-control', idProp );
const descriptionId = `${ id }__description`;

return (
<Dropdown
popoverProps={ {
Expand All @@ -51,19 +58,24 @@ function DuotoneControl( {
aria-haspopup="true"
aria-expanded={ isOpen }
onKeyDown={ openOnArrowDown }
label={ __( 'Apply duotone filter' ) }
label={ actionLabel }
icon={ toolbarIcon }
/>
);
} }
renderContent={ () => (
<MenuGroup label={ __( 'Duotone' ) }>
<div className="block-editor-duotone-control__description">
<div
id={ descriptionId }
className="block-editor-duotone-control__description"
>
{ __(
'Create a two-tone color effect without losing your original image.'
) }
</div>
<DuotonePicker
aria-label={ actionLabel }
aria-describedby={ descriptionId }
colorPalette={ colorPalette }
duotonePalette={ duotonePalette }
disableCustomColors={ disableCustomColors }
Expand Down
3 changes: 2 additions & 1 deletion packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- `SearchControl`: polish metrics for `compact` size variant ([#54663](https://github.com/WordPress/gutenberg/pull/54663)).
- `Button`: deprecating `isPressed` prop in favour of `aria-pressed` ([#54740](https://github.com/WordPress/gutenberg/pull/54740)).
- `DuotonePicker/ColorListPicker`: Adds appropriate label and description to 'Duotone Filter' picker ([#54473](https://github.com/WordPress/gutenberg/pull/54473)).

### Bug Fix

Expand Down Expand Up @@ -39,7 +40,7 @@
- `DuotonePicker/ColorListPicker`: Adds appropriate labels to 'Duotone Filter' color pickers ([#54468](https://github.com/WordPress/gutenberg/pull/54468)).
- `SearchControl`: support new `40px` and `32px` sizes ([#54548](https://github.com/WordPress/gutenberg/pull/54548)).
- `FormTokenField`: Add `tokenizeOnBlur` prop to add any incompleteTokenValue as a new token when field loses focus ([#54445](https://github.com/WordPress/gutenberg/pull/54445)).
- `Sandbox`: Add `tabIndex` prop ([#54408](https://github.com/WordPress/gutenberg/pull/54408)).
- `Sandbox`: Add `tabIndex` prop ([#54408](https://github.com/WordPress/gutenberg/pull/54408)).

### Bug Fix

Expand Down
6 changes: 5 additions & 1 deletion packages/components/src/duotone-picker/duotone-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,23 @@ function DuotonePicker( {
onChange,
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledby,
...otherProps
}: DuotonePickerProps ) {
const [ defaultDark, defaultLight ] = useMemo(
() => getDefaultColors( colorPalette ),
[ colorPalette ]
);

const isUnset = value === 'unset';
const unsetOptionLabel = __( 'Unset' );

const unsetOption = (
<CircularOptionPicker.Option
key="unset"
value="unset"
isSelected={ isUnset }
tooltipText={ __( 'Unset' ) }
tooltipText={ unsetOptionLabel }
aria-label={ unsetOptionLabel }
className="components-duotone-picker__color-indicator"
onClick={ () => {
onChange( isUnset ? undefined : 'unset' );
Expand Down Expand Up @@ -154,6 +157,7 @@ function DuotonePicker( {

return (
<CircularOptionPicker
{ ...otherProps }
{ ...metaProps }
options={ unsetable ? [ unsetOption, ...options ] : options }
actions={
Expand Down

0 comments on commit 15c2dd9

Please sign in to comment.