downshift
downshift copied to clipboard
[BUG] Problem with virtualised lists and arrow key navigation
Versions
-
downshift
version:6.1.7
-
npm
(oryarn
) version:yarn 1.22.15
The issue
Hello, when using useCombobox
, I have run into an interesting issue where virtualising my items and using "Up" on the arrow keys will give me an error (attached below).
This issue is tangentially related to these issues here:
- https://github.com/downshift-js/downshift/issues/1041
- https://github.com/downshift-js/downshift/pull/1045
Mine differs from this as I am using a permanent fixture that I want to be accessible using the keyboard (like it's a regular item) so I am essentially making into into a "fake" item and handling it differently within the stateReducer
(this "item" is used to select user input as a custom item"
The problem is that I don't always want to show this fixture so sometimes it is disabled
, this is a problem when trying to run the getNextNonDisabledIndex
function because the item that I want to highlight has not mounted yet and therefore is not in the itemRefs
object.
Reproduction
This sandbox reproduces my issue if you do the following:
- Select one of the items that are visible on mount
- Focus the text input and delete the input value
- Press up on the arrow keys
https://codesandbox.io/s/autumn-breeze-0m82p?file=/src/index.js
Suggestions
I have created a PR with my suggested solution here: https://github.com/downshift-js/downshift/pull/1348