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

[docs] Fix a11y in Menu demos #30378

Merged
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
10 changes: 9 additions & 1 deletion docs/src/pages/components/menus/AccountMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ export default function AccountMenu() {
<Typography sx={{ minWidth: 100 }}>Contact</Typography>
<Typography sx={{ minWidth: 100 }}>Profile</Typography>
<Tooltip title="Account settings">
<IconButton onClick={handleClick} size="small" sx={{ ml: 2 }}>
<IconButton
onClick={handleClick}
size="small"
sx={{ ml: 2 }}
aria-controls={open ? 'account-menu' : undefined}
aria-haspopup="true"
aria-expanded={open ? 'true' : undefined}
>
<Avatar sx={{ width: 32, height: 32 }}>M</Avatar>
</IconButton>
</Tooltip>
</Box>
<Menu
anchorEl={anchorEl}
id="account-menu"
open={open}
onClose={handleClose}
onClick={handleClose}
Expand Down
10 changes: 9 additions & 1 deletion docs/src/pages/components/menus/AccountMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ export default function AccountMenu() {
<Typography sx={{ minWidth: 100 }}>Contact</Typography>
<Typography sx={{ minWidth: 100 }}>Profile</Typography>
<Tooltip title="Account settings">
<IconButton onClick={handleClick} size="small" sx={{ ml: 2 }}>
<IconButton
onClick={handleClick}
size="small"
sx={{ ml: 2 }}
aria-controls={open ? 'account-menu' : undefined}
aria-haspopup="true"
aria-expanded={open ? 'true' : undefined}
>
<Avatar sx={{ width: 32, height: 32 }}>M</Avatar>
</IconButton>
</Tooltip>
</Box>
<Menu
anchorEl={anchorEl}
id="account-menu"
open={open}
onClose={handleClose}
onClick={handleClose}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/menus/BasicMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function BasicMenu() {
<div>
<Button
id="basic-button"
aria-controls="basic-menu"
aria-controls={open ? 'basic-menu' : undefined}
Copy link
Member

Choose a reason for hiding this comment

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

👍 Looks correct based on https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-controls

A combobox element has aria-controls set to a value that refers to the element that serves as the popup. The aria-controls only needs to be set when the popup is visible, but it is valid and easier to program to reference an element that is not visible.

Copy link
Member

@oliviertassinari oliviertassinari Dec 24, 2021

Choose a reason for hiding this comment

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

I guess that in our case, it's even more than non-visible => non-existent.

On a different note, the thread in w3c/aria#995 (comment) suggests that the attribute is close to poop.

aria-haspopup="true"
aria-expanded={open ? 'true' : undefined}
onClick={handleClick}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/menus/BasicMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function BasicMenu() {
<div>
<Button
id="basic-button"
aria-controls="basic-menu"
aria-controls={open ? 'basic-menu' : undefined}
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
aria-haspopup="true"
aria-expanded={open ? 'true' : undefined}
onClick={handleClick}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/menus/CustomizedMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function CustomizedMenus() {
<div>
<Button
id="demo-customized-button"
aria-controls="demo-customized-menu"
aria-controls={open ? 'demo-customized-menu' : undefined}
aria-haspopup="true"
aria-expanded={open ? 'true' : undefined}
variant="contained"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/menus/CustomizedMenus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function CustomizedMenus() {
<div>
<Button
id="demo-customized-button"
aria-controls="demo-customized-menu"
aria-controls={open ? 'demo-customized-menu' : undefined}
aria-haspopup="true"
aria-expanded={open ? 'true' : undefined}
variant="contained"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/menus/FadeMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function FadeMenu() {
<div>
<Button
id="fade-button"
aria-controls="fade-menu"
aria-controls={open ? 'fade-menu' : undefined}
aria-haspopup="true"
aria-expanded={open ? 'true' : undefined}
onClick={handleClick}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/menus/FadeMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function FadeMenu() {
<div>
<Button
id="fade-button"
aria-controls="fade-menu"
aria-controls={open ? 'fade-menu' : undefined}
aria-haspopup="true"
aria-expanded={open ? 'true' : undefined}
onClick={handleClick}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/menus/LongMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function LongMenu() {
<IconButton
aria-label="more"
id="long-button"
aria-controls="long-menu"
aria-controls={open ? 'long-menu' : undefined}
aria-expanded={open ? 'true' : undefined}
aria-haspopup="true"
onClick={handleClick}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/menus/LongMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function LongMenu() {
<IconButton
aria-label="more"
id="long-button"
aria-controls="long-menu"
aria-controls={open ? 'long-menu' : undefined}
aria-expanded={open ? 'true' : undefined}
aria-haspopup="true"
onClick={handleClick}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/menus/PositionedMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function PositionedMenu() {
<div>
<Button
id="demo-positioned-button"
aria-controls="demo-positioned-menu"
aria-controls={open ? 'demo-positioned-menu' : undefined}
aria-haspopup="true"
aria-expanded={open ? 'true' : undefined}
onClick={handleClick}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/menus/PositionedMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function PositionedMenu() {
<div>
<Button
id="demo-positioned-button"
aria-controls="demo-positioned-menu"
aria-controls={open ? 'demo-positioned-menu' : undefined}
aria-haspopup="true"
aria-expanded={open ? 'true' : undefined}
onClick={handleClick}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ export default function useAutocomplete(props) {
// only have an opinion about this when closed
'aria-activedescendant': popupOpen ? '' : null,
'aria-autocomplete': autoComplete ? 'both' : 'list',
'aria-controls': listboxAvailable ? `${id}-listbox` : null,
'aria-controls': listboxAvailable ? `${id}-listbox` : undefined,
// Disable browser's suggestion that might overlap with the popup.
// Handle autocomplete but not autofill.
autoComplete: 'off',
Expand Down