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

[Menu] Fix menu being focused instead of item when opening #17506

Merged
merged 4 commits into from
Sep 23, 2019

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Sep 21, 2019

Closes #16644

The first (selected) item is now focused when opening instead of the [role="menu"] itself following https://www.w3.org/TR/wai-aria-practices/#menu.

As far as I can tell the the roving tabIndex is not necessary for an open/close menu. It might make more sense to move this logic into the MenuList that could act as the listbox implementation. This would make this component useful for composition. Right now the composition demo we have makes the menu inaccessible.

I'll make a follow-up PR refactoring the Menu(List) unit test to use testing library to have enough confidence in moving a11y into MenuList.

@eps1lon eps1lon added accessibility a11y component: menu This is the name of the generic UI component, not the React module! labels Sep 21, 2019
@@ -35,7 +35,7 @@ chai.use((chaiAPI, utils) => {
currentNode !== document.documentElement &&
ariaHidden === false
) {
ariaHidden = element.getAttribute('aria-hidden') === 'true';
ariaHidden = currentNode.getAttribute('aria-hidden') === 'true';
Copy link
Member Author

Choose a reason for hiding this comment

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

🤦‍♂️

Good news is that this functionality will be moved into testing-library. We'll probably expose some isAccessible utility which we can use.

button.focus();
fireEvent.click(button);
button.click();
Copy link
Member Author

@eps1lon eps1lon Sep 21, 2019

Choose a reason for hiding this comment

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

This is safer because jsodm only checks disabled on click not when dispatching a click event. See jsdom/jsdom#2665

@mui-pr-bot
Copy link

mui-pr-bot commented Sep 21, 2019

Details of bundle changes.

Comparing: 9c4c8ae...78f3143

bundle parsed diff gzip diff prev parsed current parsed prev gzip current gzip
@material-ui/core -0.02% -0.03% 331,822 331,747 90,593 90,570
@material-ui/core/Paper 0.00% 0.00% 68,710 68,710 20,474 20,474
@material-ui/core/Paper.esm 0.00% 0.00% 62,147 62,147 19,217 19,217
@material-ui/core/Popper 0.00% 0.00% 28,397 28,397 10,159 10,159
@material-ui/core/Textarea 0.00% 0.00% 5,082 5,082 2,136 2,136
@material-ui/core/TrapFocus 0.00% 0.00% 3,766 3,766 1,596 1,596
@material-ui/core/styles/createMuiTheme 0.00% 0.00% 16,348 16,348 5,818 5,818
@material-ui/core/useMediaQuery 0.00% 0.00% 2,488 2,488 1,050 1,050
@material-ui/lab 0.00% 0.00% 143,172 143,172 43,751 43,751
@material-ui/styles 0.00% 0.00% 51,469 51,469 15,305 15,305
@material-ui/system 0.00% 0.00% 15,581 15,581 4,341 4,341
Button 0.00% 0.00% 78,682 78,682 24,047 24,047
Modal 0.00% 0.00% 14,542 14,542 5,113 5,113
Portal 0.00% 0.00% 2,907 2,907 1,318 1,318
Rating 0.00% 0.00% 70,013 70,013 21,867 21,867
Slider 0.00% 0.00% 75,154 75,154 23,217 23,217
colorManipulator 0.00% 0.00% 3,835 3,835 1,519 1,519
docs.landing 0.00% 0.00% 54,267 54,267 14,344 14,344
docs.main -0.01% -0.01% 581,743 581,670 186,249 186,236
packages/material-ui/build/umd/material-ui.production.min.js -0.02% +0.01% 🔺 302,677 302,615 87,045 87,052

Generated by 🚫 dangerJS against 78f3143

@eps1lon
Copy link
Member Author

eps1lon commented Sep 21, 2019

Visual diff is expected: https://www.argos-ci.com/mui-org/material-ui/builds/54490

@eps1lon eps1lon marked this pull request as ready for review September 21, 2019 11:00
@@ -25,10 +25,10 @@ You can learn more about the difference by [reading this guide](/guides/minimizi
| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name">anchorEl</span> | <span class="prop-type">object<br>&#124;&nbsp;func</span> | | The DOM element used to set the position of the menu. |
| <span class="prop-name">autoFocus</span> | <span class="prop-type">bool</span> | | If `true` (default), the menu list (possibly a particular item depending on the menu variant) will receive focus on open. |
| <span class="prop-name">autoFocus</span> | <span class="prop-type">bool</span> | <span class="prop-default">true</span> | If `true` (Default) will focus the `[role="menu"]` if no focusable child is found. Disabled children are not focusable. If you set this prop to `false` focus will be placed on the parent modal container. This has severe accessibility implications and should only be considered if you manage focus otherwise. |
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I would change the last part but I can't think of an alternative right now :P

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem is that these "disable focus managment" props were outside contributions without a test or use case. There's probably a good reason to have them but my guess is that 99% of the time you shouldn't touch these.

@@ -217,6 +229,7 @@ describe('<Menu /> integration', () => {
const { getAllByRole } = render(
<OpenMenu variant="selectedMenu">
<MenuItem />
getByRole
Copy link
Member

Choose a reason for hiding this comment

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

a small mistake? 🥚

Copy link
Member Author

Choose a reason for hiding this comment

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

Who put that there? 😄

@eps1lon eps1lon merged commit d237432 into mui:master Sep 23, 2019
@eps1lon eps1lon deleted the fix/Menu/focus-first-on-open branch September 23, 2019 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility a11y component: menu This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Menu initial focus does not follow WAI-ARIA recommendations
4 participants