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

Stop handled key events propagating #633

Merged
merged 1 commit into from
Dec 13, 2018
Merged

Stop handled key events propagating #633

merged 1 commit into from
Dec 13, 2018

Conversation

johnjesse
Copy link
Contributor

What: Stop the propagation of keydown events that have been handled by downshift

Why: If I am using downshift inside a component that is also handling key events then it shouldn't be receiving them if downshift has already taken action

How: using event.stopPropagation()

Checklist:

  • Documentation "N/A" - I think there's nothing to add to the documentation about this, the user can still disable this behaviour (as they could before) by setting event.preventDownshiftDefault, so I don't think there needs to be a new addition to the dos?
  • Tests
  • Ready to be merged
  • Added myself to contributors table - the add-contributors script failed on my windows machine

This fixes issue #630

@johnjesse
Copy link
Contributor Author

Also, running the tests locally
npm run build-and-test failed for me... within the build-and-test script, not sure what the error was
npm run test:cypress had one failing test

but I think this might just be my machine, as they both failed locally before my changes,

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent. Thank you!

@kentcdodds
Copy link
Member

I wonder if we should use stopPropagation for every event 🤔 (and not just these specific keys).

@johnjesse
Copy link
Contributor Author

Potentially, I think if we are calling preventDefault it's a good indicator that we probably want to call stopPropagation.

I would be a little wary of overusing stopPropagation. Calling stopPropagation is effectively cancelling the event and saying that no-one else can handle it. I have also sees varying accounts for when/if you should call stop propagation, see https://css-tricks.com/dangers-stopping-event-propagation/ for instance.

I think we can safely use stopPropagation when you are convinced that nothing else should be doing something with that event (it feels like this is probably generally true). In our case, you are using the keyboard interaction to navigate the downshift control/select an element/close the downshift control. In all cases the keyboard interaction is within the context of the downshift control and doing something to that control. The same keys should not be being re-used for some other functionality whilst we're within the context of downshift. Maybe we review the other event handlers and decide if they fit the same criteria?

@kentcdodds
Copy link
Member

That makes sense. I think we'll stick with this until someone complains 👍 Thanks!

@kentcdodds kentcdodds merged commit 5084cd0 into downshift-js:master Dec 13, 2018
@kentcdodds
Copy link
Member

🎉 This PR is included in version 3.1.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

kentcdodds pushed a commit that referenced this pull request Jan 8, 2019
This reverts commit 5084cd0.

The changes as part of #633 were incomplete, did not provide a way to allow downshift to handle event and optionally stop propagation, and incorrectly always stopped event propagation on Escape Keydown events.

See discussion in #642 and #643

Whilst we may want to do some stopping of propagation, for now this just reverts that PR so that the events are always propagated.
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.

2 participants