Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick "ToggleGroupControl: Don't autoselect option on first group focus (#65892)" to wp/6.7 #66046

Merged
merged 1 commit into from
Oct 14, 2024
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
13 changes: 4 additions & 9 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

## Unreleased

### Bug Fixes

- `Tooltip`: add `aria-describedby` to the anchor only if not redundant ([#65989](https://github.com/WordPress/gutenberg/pull/65989)).
- `PaletteEdit`: dedupe palette element slugs ([#65772](https://github.com/WordPress/gutenberg/pull/65772)).

## 28.9.0 (2024-10-03)
## 28.8.6 (2024-10-14)

### Bug Fixes

Expand All @@ -18,9 +13,9 @@
- `Composite`: make items tabbable if active element gets removed ([#65720](https://github.com/WordPress/gutenberg/pull/65720)).
- `DatePicker`: Use compact button size. ([#65653](https://github.com/WordPress/gutenberg/pull/65653)).
- `DropZone`: fix class names on drop ([#65798](https://github.com/WordPress/gutenberg/pull/65798)).

### Enhancements

- `Tooltip`: add `aria-describedby` to the anchor only if not redundant ([#65989](https://github.com/WordPress/gutenberg/pull/65989)).
- `PaletteEdit`: dedupe palette element slugs ([#65772](https://github.com/WordPress/gutenberg/pull/65772)).
Comment on lines +16 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these two fixes cherry-picked into the branch, too? The rest looks great.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are moved from the above. They seem to be backported too!

What should we do if these were not backported, though? Should we leave them in the "Unreleased" section or remove them?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove them completely if not cherry-picked before.

- `ToggleGroupControl`: Don't autoselect option on first group focus ([#65892](https://github.com/WordPress/gutenberg/pull/65892)).
- `Guide`: Update finish button to use the new default size ([#65680](https://github.com/WordPress/gutenberg/pull/65680)).

## 28.8.0 (2024-09-19)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ exports[`ToggleGroupControl controlled should render correctly with icons 1`] =
class="components-toggle-group-control emotion-8 emotion-9"
data-wp-c16t="true"
data-wp-component="ToggleGroupControl"
id="toggle-group-control-as-radio-group-11"
id="toggle-group-control-as-radio-group-12"
role="radiogroup"
>
<div
Expand All @@ -258,7 +258,7 @@ exports[`ToggleGroupControl controlled should render correctly with icons 1`] =
data-value="uppercase"
data-wp-c16t="true"
data-wp-component="ToggleGroupControlOptionBase"
id="toggle-group-control-as-radio-group-11-30"
id="toggle-group-control-as-radio-group-12-32"
role="radio"
type="button"
value="uppercase"
Expand Down Expand Up @@ -297,7 +297,7 @@ exports[`ToggleGroupControl controlled should render correctly with icons 1`] =
data-value="lowercase"
data-wp-c16t="true"
data-wp-component="ToggleGroupControlOptionBase"
id="toggle-group-control-as-radio-group-11-31"
id="toggle-group-control-as-radio-group-12-33"
role="radio"
type="button"
value="lowercase"
Expand Down Expand Up @@ -493,7 +493,7 @@ exports[`ToggleGroupControl controlled should render correctly with text options
class="components-toggle-group-control emotion-8 emotion-9"
data-wp-c16t="true"
data-wp-component="ToggleGroupControl"
id="toggle-group-control-as-radio-group-10"
id="toggle-group-control-as-radio-group-11"
role="radiogroup"
>
<div
Expand All @@ -506,7 +506,7 @@ exports[`ToggleGroupControl controlled should render correctly with text options
data-value="rigas"
data-wp-c16t="true"
data-wp-component="ToggleGroupControlOptionBase"
id="toggle-group-control-as-radio-group-10-28"
id="toggle-group-control-as-radio-group-11-30"
role="radio"
type="button"
value="rigas"
Expand All @@ -528,7 +528,7 @@ exports[`ToggleGroupControl controlled should render correctly with text options
data-value="jack"
data-wp-c16t="true"
data-wp-component="ToggleGroupControlOptionBase"
id="toggle-group-control-as-radio-group-10-29"
id="toggle-group-control-as-radio-group-11-31"
role="radio"
type="button"
value="jack"
Expand Down
13 changes: 13 additions & 0 deletions packages/components/src/toggle-group-control/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@ describe.each( [
expect( mockOnChange ).toHaveBeenCalledWith( 'rigas' );
} );

it( 'should not set a value on focus', async () => {
render(
<Component label="Test Toggle Group Control">{ options }</Component>
);

const radio = screen.getByRole( 'radio', { name: 'R' } );
expect( radio ).not.toBeChecked();

await press.Tab();
expect( radio ).toHaveFocus();
expect( radio ).not.toBeChecked();
} );

it( 'should render tooltip where `showTooltip` === `true`', async () => {
render(
<Component label="Test Toggle Group Control">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ function ToggleGroupControlOptionBase(
value,
children,
showTooltip = false,
onFocus: onFocusProp,
disabled,
...otherButtonProps
} = buttonProps;
Expand Down Expand Up @@ -134,7 +133,6 @@ function ToggleGroupControlOptionBase(
<button
{ ...commonProps }
disabled={ disabled }
onFocus={ onFocusProp }
aria-pressed={ isPressed }
type="button"
onClick={ buttonOnClick }
Expand All @@ -144,19 +142,17 @@ function ToggleGroupControlOptionBase(
) : (
<Ariakit.Radio
disabled={ disabled }
render={
<button
type="button"
{ ...commonProps }
onFocus={ ( event ) => {
onFocusProp?.( event );
if ( event.defaultPrevented ) {
return;
}
toggleGroupControlContext.setValue( value );
} }
/>
}
onFocusVisible={ () => {
// Conditions ensure that the first visible focus to a radio group
// without a selected option will not automatically select the option.
if (
toggleGroupControlContext.value !== null ||
toggleGroupControlContext.activeItemIsNotFirstItem?.()
) {
toggleGroupControlContext.setValue( value );
}
} }
render={ <button type="button" { ...commonProps } /> }
value={ value }
>
<ButtonContentView>{ children }</ButtonContentView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ function UnforwardedToggleGroupControlAsRadioGroup(
const groupContextValue = useMemo(
() =>
( {
activeItemIsNotFirstItem: () =>
radio.getState().activeId !== radio.first(),
baseId,
isBlock: ! isAdaptiveWidth,
size,
value: selectedValue,
setValue,
} ) as ToggleGroupControlContextProps,
[ baseId, isAdaptiveWidth, size, selectedValue, setValue ]
[ baseId, isAdaptiveWidth, radio, size, selectedValue, setValue ]
);

return (
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/toggle-group-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export type ToggleGroupControlProps = Pick<
};

export type ToggleGroupControlContextProps = {
activeItemIsNotFirstItem?: () => boolean;
isDeselectable?: boolean;
baseId: string;
isBlock: ToggleGroupControlProps[ 'isBlock' ];
Expand Down
Loading