Skip to content

Conversation

@ze-flo
Copy link
Contributor

@ze-flo ze-flo commented Sep 26, 2024

Description

This PR bumps @zendeskgarden/container-menu to v0.5.0 with two key changes:

  1. Menu now returns focus to the trigger before calling onChange, improving A11y for implementations that open modals after selection (see chore: focus return demo - ⚠️ DO NOT MERGE! ⚠️  #1931)
  2. defaultFocusedValue only applies when opening the menu via keyboard, aligning with APG examples

These changes improve accessibility and user experience, especially for keyboard navigation and complex UI interactions.

💥 BREAKING CHANGE:

Menu: new restoreFocus prop (default: true) returns focus to trigger after menu interaction. When menu expansion is controlled to allow multiple item selection, set restoreFocus={false} and manage trigger focus manually on close.

Detail

  • Bump @zendeskgarden/container-menu to v0.5.0
  • Update specs to reflect focus behavior when using defaultFocusedValue
  • Adds breaking change detail to v9 migration doc.

Checklist

  • 👌 design updates will be Garden Designer approved (add the designer as a reviewer)
  • 🌐 demo is up-to-date (npm start)
  • ⬅️ renders as expected with reversed (RTL) direction
  • ⚫ renders as expected in dark mode
  • 🤘 renders as expected with Bedrock CSS (?bedrock)
  • 💂‍♂️ includes new unit tests. Maintain existing coverage (always >= 96%)
  • ♿ tested for WCAG 2.1 AA accessibility compliance
  • 📝 tested in Chrome, Firefox, Safari, and Edge

Comment on lines +151 to +166
const trigger = getByRole('button');

// open menu with onClick
await user.click(trigger);
const item = getByTestId('item-02');
// focus remains on trigger with mouseEvents
expect(trigger).toHaveFocus();

// close menu
await user.click(trigger);
expect(item).not.toBeVisible();

// open menu with keyboard
trigger.focus();
await user.keyboard(' ');
// focus is on the focused item associated with `defaultFocusedValue`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

zendeskgarden/react-containers#660 changed the focus behavior when using defaultFocusedValue.

Copy link
Member

@jzempel jzempel left a comment

Choose a reason for hiding this comment

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

The Menu API (and Storybook controls) are missing the new restoreFocus prop. This needs to be specified under /types.

"@floating-ui/react-dom": "^2.0.0",
"@zendeskgarden/container-combobox": "^2.0.0",
"@zendeskgarden/container-menu": "^0.4.0",
"@zendeskgarden/container-menu": "0.5.0",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"@zendeskgarden/container-menu": "0.5.0",
"@zendeskgarden/container-menu": "^0.5.0",

These dependencies use range notation

Comment on lines 123 to 124
after menu interaction. To keep the dropdown open on selection,
set `restoreFocus={false}` and manage focus manually.
Copy link
Member

Choose a reason for hiding this comment

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

Not sure I understand this. Wouldn't the isExpanded controlled prop be the mechanism for keeping the menu open?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was referring to cases when a users chooses to keep the menu open after selecting an item within an ItemGroup of type checkbox. This demo showcases this pattern.

It probably makes more sense to rephrase it as such:

`Menu`: new `restoreFocus` prop (default: `true`) returns focus to trigger
  after menu interaction. If keeping the dropdown open on selection is required,
  set `restoreFocus={false}` and manage focus manually.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

This still makes it sound like there is a causal relationship between keeping the menu open and setting restoreFocus to false.

Comment on lines 121 to 124
- `Menu`: value `auto` is no longer valid for the `fallbackPlacements` prop.
- `Menu`: new `restoreFocus` prop (default: `true`) returns focus to trigger
after menu interaction. To keep the dropdown open on selection,
set `restoreFocus={false}` and manage focus manually.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- `Menu`: value `auto` is no longer valid for the `fallbackPlacements` prop.
- `Menu`: new `restoreFocus` prop (default: `true`) returns focus to trigger
after menu interaction. To keep the dropdown open on selection,
set `restoreFocus={false}` and manage focus manually.
- `Menu`
- value `auto` is no longer valid for the `fallbackPlacements` prop.
- new `restoreFocus` prop (default: `true`) returns focus to trigger
after menu interaction. When menu expansion is controlled to allow
multiple item selection, set `restoreFocus={false}` and manage trigger
focus manually on close.

Copy link
Contributor Author

@ze-flo ze-flo Sep 26, 2024

Choose a reason for hiding this comment

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

Couldn't have written it better myself. Thank you! 💯

Copy link
Member

@jzempel jzempel left a comment

Choose a reason for hiding this comment

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

🚢

@ze-flo ze-flo merged commit 69d513c into main Sep 26, 2024
14 checks passed
@ze-flo ze-flo deleted the ze-flo/menu-restore-focus-fix branch September 26, 2024 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants