I'm currently working on accessibility in a web application using React & Ant Design's Select component. aria-expanded
is set to false
string.
I want to use React useState
to toggle aria-expanded="false"
so that the aria label in the screen reader can read back wether the dropdown is open or closed.
The idea is to take the default state and use it in the useState hook like this:
const [selectAria, setSelectAria] = useState('false');
<Select
name="someName"
id="someID"
onSelect={(value) => handleChangeSelect(value)}
aria-label={
selectAria ? 'i am closed' : 'i am open '
}
aria-expanded={selectAria}
>
The screen reader is only able to recognize when the initial state. After I select an option, and the dropdown is closed, it does not read back the new state.
Is it possible to do this in React hooks? Is it possible to access the aria-expanded
attribute in useState
along with the boolean value? I haven't worked on advanced accessibility and have to stick with the antD library for this. Thanks in advance.