Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/block-library/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

### Bug Fixes

- Cover: Use the new toggle-button presentation for the placeholder overlay color palette ([#82023](https://github.com/WordPress/gutenberg/pull/82023)).
- Columns: Preserve individual Column attributes supported by Group, including styles and layouts, when transforming to Row or Grid.
- Gallery: Don't offer the Image and Grid transforms while the block is in dynamic mode, where it has no inner blocks to convert ([#82009](https://github.com/WordPress/gutenberg/pull/82009)).
- Icon: Apply only padding to the inner SVG in the editor, so margin is no longer applied twice compared to the front end ([#81292](https://github.com/WordPress/gutenberg/pull/81292)).
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/cover/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ function CoverEdit( {
value={ overlayColor.color }
onChange={ onSetOverlayColor }
clearable={ false }
asButtons
presentation="toggle-buttons"
aria-label={ __( 'Overlay color' ) }
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

### Bug Fixes

- `PaletteEdit`: Expose color, gradient, and duotone swatches as command buttons because activating them opens an editor instead of selecting a value. Add a `presentation` prop to `CircularOptionPicker`, `ColorPalette`, `GradientPicker`, and `DuotonePicker`, and deprecate `asButtons` in favor of `presentation="toggle-buttons"` ([#82023](https://github.com/WordPress/gutenberg/pull/82023)).
- `ConfirmDialog`: Preserve `title` as the dialog's accessible name when the header is hidden ([#81847](https://github.com/WordPress/gutenberg/pull/81847)).
- `DuotonePicker`: Do not render the custom controls wrapper when `disableCustomDuotone` is set, so a read-only picker no longer adds trailing padding below its swatches ([#81605](https://github.com/WordPress/gutenberg/pull/81605)).
- `DuotonePicker`: Stop the duotone bar offering to move its control points. It announced that arrow keys and dragging change the gradient position, but a duotone is two colors with no positions, so the move was discarded. `CustomGradientBar` gains a `disablePositioning` prop for this ([#81850](https://github.com/WordPress/gutenberg/pull/81850)).
Expand Down
12 changes: 8 additions & 4 deletions packages/components/src/circular-option-picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,20 @@ The child elements.

- Required: No

### `asButtons`: `boolean`
### `presentation`: `'listbox' | 'toggle-buttons' | 'command-buttons'`

Whether the control should present as a set of buttons, each with its own tab stop.
Controls the swatches' interaction and accessibility semantics.

- `listbox` uses one tab stop for the picker. Arrow keys move between options. Options expose selection with `aria-selected`.
- `toggle-buttons` uses a tab stop for each swatch. Swatches expose selection with `aria-pressed`.
- `command-buttons` uses a tab stop for each swatch. Swatches do not expose selection. Use this presentation when each swatch runs a command, such as opening an editor.

- Required: No
- Default: `false`
- Default: `listbox`

### `loop`: `boolean`

Prevents keyboard interaction from wrapping around. Only used when `asButtons` is not true.
Prevents arrow-key navigation from wrapping around. Only used with the `listbox` presentation.

- Required: No
- Default: `true`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ export function Option( {
tooltipText,
...additionalProps
}: OptionProps ) {
const { baseId, setActiveId } = useContext( CircularOptionPickerContext );
// Preserve the historical toggle-button fallback when this public
// subcomponent is rendered without a parent picker.
const { baseId, presentation = 'toggle-buttons' } = useContext(
CircularOptionPickerContext
);
const id = useInstanceId(
Option,
baseId || 'components-circular-option-picker__option'
Expand All @@ -91,20 +95,24 @@ export function Option( {
...additionalProps,
};

const isListbox = setActiveId !== undefined;
const optionControl = isListbox ? (
<OptionAsOption
{ ...commonProps }
label={ tooltipText }
isSelected={ isSelected }
/>
) : (
<OptionAsButton
{ ...commonProps }
label={ tooltipText }
isPressed={ isSelected }
/>
);
const optionControl =
presentation === 'listbox' ? (
<OptionAsOption
{ ...commonProps }
label={ tooltipText }
isSelected={ isSelected }
/>
) : (
<OptionAsButton
{ ...commonProps }
label={ tooltipText }
isPressed={
presentation === 'toggle-buttons'
? !! isSelected
: undefined
}
/>
);

return (
<div
Expand All @@ -114,7 +122,9 @@ export function Option( {
) }
>
{ optionControl }
{ isSelected && <Icon icon={ check } { ...selectedIconProps } /> }
{ presentation !== 'command-buttons' && isSelected && (
<Icon icon={ check } { ...selectedIconProps } />
) }
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import {
ButtonAction,
DropdownLinkAction,
} from './circular-option-picker-actions';
import {
resolveCircularOptionPickerPresentation,
warnIfCircularOptionPickerAsButtonsIsSet,
} from './utils';

/**
*`CircularOptionPicker` is a component that displays a set of options as circular buttons.
Expand Down Expand Up @@ -83,6 +87,7 @@ function ListboxCircularOptionPicker(
baseId,
activeId,
setActiveId,
presentation: 'listbox' as const,
} ),
[ baseId, activeId, setActiveId ]
);
Expand Down Expand Up @@ -111,13 +116,21 @@ function ListboxCircularOptionPicker(
function ButtonsCircularOptionPicker(
props: ButtonsCircularOptionPickerProps
) {
const { actions, options, children, baseId, ...additionalProps } = props;
const {
actions,
options,
children,
baseId,
presentation,
...additionalProps
} = props;

const contextValue = useMemo(
() => ( {
baseId,
presentation,
} ),
[ baseId ]
[ baseId, presentation ]
);

return (
Expand All @@ -134,23 +147,29 @@ function ButtonsCircularOptionPicker(
function CircularOptionPicker( props: CircularOptionPickerProps ) {
const {
asButtons,
presentation,
loop,
actions: actionsProp,
options: optionsProp,
children,
className,
...additionalProps
} = props;
warnIfCircularOptionPickerAsButtonsIsSet(
'CircularOptionPicker',
asButtons
);
const resolvedPresentation = resolveCircularOptionPickerPresentation(
presentation,
asButtons
);

const baseId = useInstanceId(
CircularOptionPicker,
'components-circular-option-picker',
additionalProps.id
);

const OptionPickerImplementation = asButtons
? ButtonsCircularOptionPicker
: ListboxCircularOptionPicker;

const actions = actionsProp ? (
<div className="components-circular-option-picker__custom-clear-wrapper">
{ actionsProp }
Expand All @@ -163,16 +182,30 @@ function CircularOptionPicker( props: CircularOptionPickerProps ) {
</div>
);

const sharedProps = {
baseId,
className: clsx( 'components-circular-option-picker', className ),
actions,
options,
children,
};

if ( resolvedPresentation === 'listbox' ) {
return (
<ListboxCircularOptionPicker
{ ...additionalProps }
{ ...sharedProps }
loop={ loop }
/>
);
}

return (
<OptionPickerImplementation
<ButtonsCircularOptionPicker
{ ...additionalProps }
baseId={ baseId }
className={ clsx( 'components-circular-option-picker', className ) }
actions={ actions }
options={ options }
>
{ children }
</OptionPickerImplementation>
{ ...sharedProps }
presentation={ resolvedPresentation }
/>
);
}

Expand Down
6 changes: 5 additions & 1 deletion packages/components/src/circular-option-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export {
ButtonAction,
DropdownLinkAction,
} from './circular-option-picker-actions';
export { getComputeCircularOptionPickerCommonProps } from './utils';
export {
getComputeCircularOptionPickerCommonProps,
resolveCircularOptionPickerPresentation,
warnIfCircularOptionPickerAsButtonsIsSet,
} from './utils';

export default CircularOptionPicker;
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ Default.args = {
options: <DefaultOptions />,
};

export const AsButtons = Template.bind( {} );
AsButtons.args = {
export const AsToggleButtons = Template.bind( {} );
AsToggleButtons.args = {
...Default.args,
asButtons: true,
presentation: 'toggle-buttons',
};

export const WithLoopingDisabled = Template.bind( {} );
Expand Down
Loading
Loading