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

Autocomplete with groups throws accessibility scanner issues #42782

Open
ArmandRedgate opened this issue Jun 28, 2024 · 0 comments
Open

Autocomplete with groups throws accessibility scanner issues #42782

ArmandRedgate opened this issue Jun 28, 2024 · 0 comments
Assignees
Labels
accessibility a11y component: autocomplete This is the name of the generic UI component, not the React module!

Comments

@ArmandRedgate
Copy link

ArmandRedgate commented Jun 28, 2024

Steps to reproduce

Link to live example

Steps:

  1. Create an autocomplete component with grouping enabled, same as the official example.
    <Autocomplete
      id="grouped-demo"
      options={options.sort((a, b) => -b.firstLetter.localeCompare(a.firstLetter))}
      groupBy={(option) => option.firstLetter}
      getOptionLabel={(option) => option.title}
      sx={{ width: 300 }}
      renderInput={(params) => <TextField {...params} label="With categories" />}
    />
  1. Open the dropdown and scan with an accessibility tool like axe DevTools
    Note: you may need to force the autocomplete to stay open while you scan with open={true}

Current behavior

I get a bunch of errors around incorrect aria roles:

image

This is because <li /> are not allowed as children of listbox.

The current role structure is:

listbox
  generic <--- the group label
  list
    option
    option
    ...
  generic
  list
    option
    ...

Expected behavior

No accessibility errors.

To achieve this, you should follow the ARIA APG Listbox pattern which forms this role structure:

listbox
  group
    presentation <--- the group label
    option
    option
    ...
  group
    presentation
    option
    ...

This can be achieved in html like this

<div role="listbox">
   <ul role="group">
     <li role="presentation">
       Group 1
     </li>
     <li role="option">
        Option 1
     </li>
     ...
   </ul>
   <ul role="group">
     <li role="presentation">
       Group 2
     </li>
     <li role="option">
       Option 1
     </li>
     ...
   </ul>
</div>

In my case, I achieved this in the Autocomplete component with fully custom rendering (renderOption, renderGroup), but I wouldn't expect most users to do this.

Context

I was trying to create a grouped autocomplete list.

My company is a paying customer, our support key / order number is 65425

Your environment

npx @mui/envinfo
  System:
    OS: Windows 11 10.0.22631
  Binaries:
    Node: 21.5.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD
    pnpm: Not Found
  Browsers:
    Chrome: Not Found
    Edge: Chromium (126.0.2592.68)

Search keywords: autocomplete accessibility roles

@ArmandRedgate ArmandRedgate added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jun 28, 2024
@zannager zannager added the component: autocomplete This is the name of the generic UI component, not the React module! label Jun 28, 2024
@siriwatknp siriwatknp added accessibility a11y and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility a11y component: autocomplete This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

4 participants