I'm in the process of building a customised, accessible select input with React.js. I need to have the up and down arrow keys function as the tab key would within the scope of select input's options.
I have a handleKeyPress function on the elements that detects when other keys are pressed (for instance 'Enter' works fine).
Here is an example option:
<li
className="oc-select-field__item"
tabIndex="0"
onClick={handleClick}
onKeyPress={handleKeyPress}
>
...and here is the handleKeyPress function
handleKeyPress = event => {
if (event.key === 40) {
console.log('Down arrow key fired'); // does not fire
}
if (event.key === 'Enter') {
console.log('Enter key fired'); // does fire
}
};
What am I doing wrong that I am not successfully detecting when the down arrow is pressed?