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

[Select][base] Keep focus on the trigger element when listbox is open #37244

Merged
merged 5 commits into from
May 16, 2023

Conversation

michaldudak
Copy link
Member

@michaldudak michaldudak commented May 11, 2023

This changes the focus behavior of the Select. Previously, when Select was expanded, the listbox received focus. Now, the trigger is always focused. This simplifies focus management and prevents stealing focus when the Select is expanded on mount.

Closes #37023

@mui-bot
Copy link

mui-bot commented May 11, 2023

Netlify deploy preview

https://deploy-preview-37244--material-ui.netlify.app/

@material-ui/unstyled: parsed: -0.57% 😍, gzip: -0.44% 😍
@mui/joy: parsed: -0.17% 😍, gzip: -0.16% 😍

Bundle size report

Details of bundle changes

Generated by 🚫 dangerJS against 873e3ac

@siriwatknp
Copy link
Member

@michaldudak It is much better! https://codesandbox.io/s/base-cra-ts-forked-1kqn3t?file=/src/App.tsx

@@ -312,24 +312,12 @@ describe('Joy <Select />', () => {
expect(getByRole('combobox')).not.to.have.attribute('aria-disabled');
});

it('indicates that activating the button displays a listbox', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

According to the ARIA spec, aria-haspopup="listbox" is applied implicitly when role="combobox", so there's no need to add it manually.

it('renders an element with listbox behavior', () => {
const { getByRole } = render(<Select defaultListboxOpen value="" />);

expect(getByRole('listbox')).toBeVisible();
});

specify('the listbox is automatically focused on open', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

It's not focused on open anymore to prevent stealing focus from other elements on the page.

@michaldudak michaldudak marked this pull request as ready for review May 12, 2023 07:12
@michaldudak michaldudak added component: select This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base labels May 12, 2023
@michaldudak michaldudak added this to the MUI Base stable release milestone May 12, 2023
Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

👍 Great improvement!

@siriwatknp siriwatknp merged commit b1b7d63 into mui:master May 16, 2023
7 checks passed
binh1298 pushed a commit to binh1298/material-ui that referenced this pull request May 17, 2023
@michaldudak michaldudak deleted the select-focus-trigger branch May 17, 2023 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: select This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Select][base] Keep focus on the trigger element
3 participants