Skip to content
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

fix(useCombobox): dispatch on Enter keydown event #1150

Merged
merged 3 commits into from
Aug 15, 2020

Conversation

silviuaavram
Copy link
Collaborator

@silviuaavram silviuaavram commented Aug 15, 2020

What:

Call dispatch on Enter keydown.
Prevent event default (form submission) if menu is open.
Do not return highlightedIndex from reducer if menu is closed.
Fix the MUI example for useSelect on the docsite.

Why:
Fixes #1114.
Also to fix other potential issues.

How:
Fix the reducer for the useCombobox hook.
Add itemsAsObjects to the MUI example useCombobox hook.
Check state.isOpen before returning a highlightedIndex in the Home/End actions.

Checklist:

  • Documentation
  • Tests
  • TypeScript Types
  • Flow Types
  • Ready to be merged

@silviuaavram silviuaavram changed the title fix(useCombobox): dispatch Enter key fix(useCombobox): dispatch on Enter keydown event Aug 15, 2020
@silviuaavram silviuaavram merged commit 541e560 into master Aug 15, 2020
@silviuaavram silviuaavram deleted the fix/state-reducer-dispatch-triggering branch August 15, 2020 10:17
@silviuaavram
Copy link
Collaborator Author

🎉 This PR is included in version 6.0.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@fabb
Copy link
Contributor

fabb commented Aug 18, 2020

Haha, this broke my workaround for the old behavior 😆
Don't get me wrong, thanks for fixing! Thankfully I had unit tests in place using @testing-library.
The funny thing was that the tests were green locally, but red on the CI server. It took me a while to find out that I locally had 6.0.2 installed, and the CI server installed 6.0.5 which already includes this fix... (yes, I'm using a package-lock.json file + run npm ci, but unfortunately this dependency is one that is hoisted via lerna and therefore bypasses the package-lock.json)

@silviuaavram
Copy link
Collaborator Author

How did you test that the submit event is not dispatched (if you did indeed manage to test it). @fabb

@fabb
Copy link
Contributor

fabb commented Aug 26, 2020

In my custom component that uses the downshift hooks, I have a few callback props that get called when some state changes (like onBlur, onSelectedItemsChanged, onInputValueChanged). In the jest tests I pass a jest mock for these props, and check how often the mock callbacks have been called and with which parameters.

My unit tests have a lot more lines than the actual implementation 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[useCombobox] InputKeyDownEnter action not triggering when focus is on the input field
2 participants