Skip to content
Closed
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 `presentation="toggle-buttons"` on the placeholder overlay color palette instead of the deprecated `asButtons` prop ([#81836](https://github.com/WordPress/gutenberg/pull/81836)).
- Columns: Preserve individual Column attributes supported by Group, including styles and layouts, when transforming to Row or Grid.
- 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)).
- Playlist: Attach the inner block drop zone to the track list, so Playlist Track blocks show insertion markers while being reordered.
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 @@
- `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)).
- `Modal`: Prevent an Escape key press that dismisses the modal from propagating to underlying overlays. ([#81785](https://github.com/WordPress/gutenberg/pull/81785))
- `BoxControl`: Update the opposite side when ALT is held on the left or right input, which each updated themselves instead ([#81530](https://github.com/WordPress/gutenberg/pull/81530)).
- `PaletteEdit`: Expose palette swatches as command buttons instead of a listbox, since activating a swatch opens the editor rather than selecting a value. Adds a `presentation` prop to `CircularOptionPicker` (`listbox` | `toggle-buttons` | `command-buttons`), forwarded through `ColorPalette`, `GradientPicker`, and `DuotonePicker`. Soft-deprecates `asButtons` (hidden from docs, still supported as an alias for `toggle-buttons`, with wrapper-level warnings) ([#81836](https://github.com/WordPress/gutenberg/pull/81836)).
- `InputControl`: Vertically center the value of date and time inputs in Safari ([#81361](https://github.com/WordPress/gutenberg/pull/81361)).
- `ControlWithError`: Re-read the target's validation message when an `invalid` event is received, so a message that changed without a re-render in between (e.g. a programmatic value change followed by a synthetic `invalid` event) is not revealed stale or empty. While a `validating` custom validity is pending, the message is left untouched so the pending indicator keeps showing ([#81440](https://github.com/WordPress/gutenberg/pull/81440)).
- `Button`: Apply the `has-text` class when the children that render the label are conditional, wrapped in an element, or preceded by other children, so that such buttons are no longer styled as icon-only buttons ([#81521](https://github.com/WordPress/gutenberg/pull/81521)).
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.
How options are presented to assistive technology.

- `listbox`: a composite listbox with `role="option"` and `aria-selected`.
- `toggle-buttons`: individual buttons with `aria-pressed` for selection.
- `command-buttons`: individual buttons without a pressed state, for actions 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 keyboard interaction from wrapping around. Only used when the resolved presentation is `listbox`. Explicit `presentation` takes precedence over `asButtons`.

- Required: No
- Default: `true`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ function UnforwardedOptionAsButton(
className?: string;
isPressed?: boolean;
label?: string;
isToggle?: boolean;
},
forwardedRef: ForwardedRef< any >
) {
const { isPressed, label, ...additionalProps } = props;
const { isPressed, label, isToggle = true, ...additionalProps } = props;
return (
<Button
__next40pxDefaultSize
{ ...additionalProps }
aria-pressed={ isPressed }
aria-pressed={ isToggle ? !! isPressed : undefined }
ref={ forwardedRef }
label={ label }
/>
Expand Down Expand Up @@ -79,7 +80,7 @@ export function Option( {
tooltipText,
...additionalProps
}: OptionProps ) {
const { baseId, setActiveId } = useContext( CircularOptionPickerContext );
const { baseId, presentation } = useContext( CircularOptionPickerContext );
const id = useInstanceId(
Option,
baseId || 'components-circular-option-picker__option'
Expand All @@ -91,20 +92,22 @@ export function Option( {
...additionalProps,
};

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

return (
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import clsx from 'clsx';
import deprecated from '@wordpress/deprecated';
import { useInstanceId } from '@wordpress/compose';
import { isRTL } from '@wordpress/i18n';
import { useMemo, useState } from '@wordpress/element';
Expand All @@ -15,6 +16,7 @@ import {
ButtonAction,
DropdownLinkAction,
} from './circular-option-picker-actions';
import { resolveCircularOptionPickerPresentation } from './utils';

/**
*`CircularOptionPicker` is a component that displays a set of options as circular buttons.
Expand Down Expand Up @@ -83,6 +85,7 @@ function ListboxCircularOptionPicker(
baseId,
activeId,
setActiveId,
presentation: 'listbox' as const,
} ),
[ baseId, activeId, setActiveId ]
);
Expand Down Expand Up @@ -111,13 +114,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 +145,34 @@ function ButtonsCircularOptionPicker(
function CircularOptionPicker( props: CircularOptionPickerProps ) {
const {
asButtons,
presentation,
loop,
actions: actionsProp,
options: optionsProp,
children,
className,
...additionalProps
} = props;

if ( asButtons && presentation === undefined ) {
deprecated( '`asButtons` prop in wp.components.CircularOptionPicker', {
since: '7.2',
alternative: 'presentation',
hint: '`asButtons={ true }` maps to `presentation="toggle-buttons"`. Use `presentation="command-buttons"` for action buttons without a pressed state.',
} );
}

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 +185,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 All @@ -181,6 +217,4 @@ CircularOptionPicker.OptionGroup = OptionGroup;
CircularOptionPicker.ButtonAction = ButtonAction;
CircularOptionPicker.DropdownLinkAction = DropdownLinkAction;

CircularOptionPicker.displayName = 'CircularOptionPicker';

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
66 changes: 65 additions & 1 deletion packages/components/src/circular-option-picker/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,77 @@ describe( 'CircularOptionPicker', () => {
} );

describe( 'when `asButtons` is true', () => {
it( 'should render as buttons', async () => {
it( 'should render as toggle buttons', async () => {
render( <CircularOptionPicker { ...DEFAULT_PROPS } asButtons /> );

expect( screen.queryByRole( 'listbox' ) ).not.toBeInTheDocument();
expect( screen.queryByRole( 'option' ) ).not.toBeInTheDocument();
expect( screen.getByRole( 'group' ) ).toBeInTheDocument();
expect( screen.getByRole( 'button' ) ).toBeInTheDocument();
expect( screen.getByRole( 'button' ) ).toHaveAttribute(
'aria-pressed',
'false'
);
expect( console ).toHaveWarned();
} );
} );

describe( 'when `presentation` is `listbox`', () => {
it( 'should render as a listbox', async () => {
render(
<CircularOptionPicker
{ ...DEFAULT_PROPS }
presentation="listbox"
/>
);

expect( screen.getByRole( 'listbox' ) ).toBeInTheDocument();
expect( screen.getByRole( 'option' ) ).toBeInTheDocument();
expect( screen.queryByRole( 'button' ) ).not.toBeInTheDocument();
} );
} );

describe( 'when `presentation` is `toggle-buttons`', () => {
it( 'should render buttons with a pressed state', async () => {
render(
<CircularOptionPicker
{ ...DEFAULT_PROPS }
presentation="toggle-buttons"
options={ [
<CircularOptionPicker.Option
key="option"
isSelected
aria-label="Selected"
/>,
] }
/>
);

const button = screen.getByRole( 'button', { name: 'Selected' } );
expect( screen.getByRole( 'group' ) ).toBeInTheDocument();
expect( button ).toHaveAttribute( 'aria-pressed', 'true' );
} );
} );

describe( 'when `presentation` is `command-buttons`', () => {
it( 'should render buttons without a pressed state', async () => {
render(
<CircularOptionPicker
{ ...DEFAULT_PROPS }
presentation="command-buttons"
options={ [
<CircularOptionPicker.Option
key="option"
isSelected
aria-label="Edit"
/>,
] }
/>
);

const button = screen.getByRole( 'button', { name: 'Edit' } );
expect( screen.getByRole( 'group' ) ).toBeInTheDocument();
expect( button ).not.toHaveAttribute( 'aria-pressed' );
} );
} );

Expand Down
Loading
Loading