-
Notifications
You must be signed in to change notification settings - Fork 936
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
[useCombobox] InputKeyDownEnter action not triggering when focus is on the input field #1114
Comments
Hi @JReinhold ! Thank you for using our library! To answer your question, I need to know what you exactly want to do when the Enter key is pressed. Because depending on that there is a correct way for each scenario.
To clarify, Hope this helps you with developing your combobox. Let me know how it goes, good luck! |
This is what I want. basically, whenever the users presses Enter, and there is only one item shown in the menu, I want to select that, regardless of it being highlighted or not. something like stateReducer: (state, { type, changes }) => {
switch (type) {
case useCombobox.stateChangeTypes.InputKeyDownEnter: {
if(shownItems.length === 1){
return { ...changes, selectedItem: shownItems[0]}
}
}
return changes;
},
This wouldn't be possible currently, since no state changes as a consequence of the
That statement confuses me, because if that was the case, why is the stateReducer triggered when pressing |
You are right, this is a bug, we should fix it. Escape, Home, End, and Enter should behave the same, as far as the |
Ok, I was wrong, I'm sorry. I will submit a PR to fix Enter. This is what prevents it from triggering the dispatch: |
Sounds good, thanks! And thanks for the support. |
🎉 This issue has been resolved in version 6.0.4 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
downshift
version:5.4.5
node
version: `12.16.3npm
(oryarn
) version:npm v6.14.4
Relevant code or config
What you did:
Had a basic combobox. Typed in the input field, and pressed the
Enter
key.What happened:
Nothing happened. I expected the action
InputKeyDownEnter
to be fired in thestateReducer
, but it didn't.Reproduction repository:
https://codesandbox.io/s/usecombobox-usage-nrqhf
Problem description:
The action
InputKeyDownEnter
only seems to get fired when user is pressingEnter
with the dropdown in focus, ie. when the user is highlighting an item in the menu with arrow keys or with the mouse. If the user presses enter just after focusing the input, or just after typing a character in the input, the action isn't dispatched.This is NOT an issue with the other built in "KeyDown" actions. The following types DOES trigger correctly:
InputKeyDownEscape
InputKeyDownEnd
InputKeyDownHome
InputKeyDownArrowDown
InputKeyDownArrowUp
Suggested solution:
Without knowing if this would be a "breaking change" or have other repercussions, I'd suggest making the
InputKeyDownEnter
action also trigger when input is in focus.Current workaround:
adding a
keydown
event listener directly on the input element is possible, but not ideal:The text was updated successfully, but these errors were encountered: