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

Lighthouse ARIA accessibility warning #778

Open
joostmeijles opened this issue Dec 3, 2020 · 2 comments
Open

Lighthouse ARIA accessibility warning #778

joostmeijles opened this issue Dec 3, 2020 · 2 comments

Comments

@joostmeijles
Copy link

I am getting a ARIA accessibility warning in Lighthouse on the following:

<div id="react-autowhatever-1" role="listbox" class="react-autosuggest__suggestions-container"></div>

My React components looks like this:

const inputProps = {
        placeholder: 'What are you looking for?',
        onChange: onChange,
        onKeyDown: onKeyDown,
        value
    }

<AutoSuggest
            suggestions={hits}
            onSuggestionsFetchRequested={onSuggestionsFetchRequested}
            onSuggestionsClearRequested={onSuggestionsClearRequested}
            getSuggestionValue={getSuggestionValue}
            renderSuggestion={renderSuggestion}
            inputProps={inputProps}
            onSuggestionSelected={suggestionSelected}
            shouldRenderSuggestions={shouldRenderSuggestions}
            focusInputOnSuggestionClick={false}
            onSuggestionHighlighted={onSuggestionHighlighted}
            multiSection={true}
            renderSectionTitle={renderSectionTitle}
            getSectionSuggestions={getSectionSuggestions}
        />

Am I missing something obvious or is this a bug?

@stephenfrancis
Copy link

I have the same problem thrown up by jest-axe:

Expected the HTML found at $('#react-autowhatever-1') to have no violations:

<div id="react-autowhatever-1" role="listbox" class="react-autosuggest__suggestions-container"></div>

Received:

"ARIA input fields must have an accessible name (aria-input-field-name)"

Fix any of the following:
  aria-label attribute does not exist or is empty
  aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty
  Element has no title attribute

You can find more information on this issue here: 
https://dequeuniversity.com/rules/axe/4.1/aria-input-field-name?application=axeAPI

I think there needs to be a way of adding a aria-label or aria-labelledby on both the div and ul elements that are marked role="listbox".

@thibaudcolas
Copy link
Contributor

thibaudcolas commented Oct 12, 2021

react-autosuggest doesn’t live up to its "WAI-ARIA compliant" promise here. But this can all be worked around with renderSuggestionsContainer:


First, the div role="listbox" supports adding any ARIA attribute via the renderSuggestionsContainer prop. Here is an example:

renderSuggestionsContainer={({ containerProps, children }) => (
    <div aria-label="Suggestions" {...containerProps}>{children}</div>
)}

This is however not appropriate anyway, as this container itself also contains a listbox. Our combobox should only have one listbox, not two. So instead, we could:

renderSuggestionsContainer={({ containerProps: {role, ...otherContainerProps}, children }) => (
    <div {...otherContainerProps}>{children}</div>
)}

This unfortunately isn’t appropriate either… as we again have no way to add a label to the listbox rendered within this container. Here is what we need instead:

renderSuggestionsContainer={({ containerProps: {role, ...otherContainerProps}, children }) => (
    <div {...otherContainerProps}>
    {React.Children.map(children, child => (
        <ItemsList {...child.props}/>
    ))}
    </div>
)}

With ItemsList being a custom copy of the library’s own ItemsList, which is straightforward enough to copy into your project. Then, it’s just a matter of adding an aria-label or aria-labelledby on the right line:

<ul role="listbox" {...theme(`${sectionPrefix}items-list`, 'itemsList')}>
.


So, to recap, that’s two bugs for react-autosuggest to fix in my opinion, even if they can be worked around:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants