-
Notifications
You must be signed in to change notification settings - Fork 939
Closed
Labels
Description
downshiftversion: 4.0.8nodeversion: 12.14.1npm(oryarn) version: yarn 1.21.1
Relevant code or config
import React from 'react'
import { render } from 'react-dom'
import { useSelect } from 'downshift'
const items = ['Apples', 'Bananas', 'Oranges']
const Select = ({ items, selectedItem }) => {
const {
getItemProps,
getLabelProps,
getMenuProps,
getToggleButtonProps,
isOpen,
} = useSelect({ items, selectedItem })
return (
<div>
<label {...getLabelProps()}>Fruit: </label>
<button {...getToggleButtonProps()}>{selectedItem}</button>
{/* <ul {...getMenuProps(isOpen ? undefined : { "aria-activedescendant": null })}> */}
<ul {...getMenuProps()}>
{isOpen &&
items.map((item, index) => (
<li key={item} {...getItemProps({ item, index })}>
{item}
</li>
))}
</ul>
</div>
)
}
const App = () => <Select items={items} selectedItem={items[0]} />
render(<App />, document.getElementById('root'))What you did:
use useSelect with controlled props (items and selectedItem)
What happened:
when used with controlled props, useSelect's getMenuProps ouputs an aria-activedescendant attribute pointing to a non-existing id (because the <li> elements are only rendered when the select is open.
Lighthouse therefore complains with "[aria-*] attributes do not have valid values".
Reproduction repository:
Problem description:
Suggested solution:
I'm currently working aroung this with {...getMenuProps(isOpen ? undefined : { "aria-activedescendant": null })} (see above), but i guess there is a better solution?
Reactions are currently unavailable