Skip to content

fix: prevent "space" on input to open dropdown #10715

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

Merged
merged 4 commits into from
Feb 10, 2018

Conversation

Owlbertz
Copy link
Contributor

I had the usecase where I used a Dropdown as a auto-completion/suggestion feature. The Dropdown was attached to an input element and shows when the input has focus. Issue was then, that everytime a space was entered into the input, the Dropdown would receive focus and prevent the typing within the input.

I am not sure, whether this is too specific or not to become part of the code base.

@IamManchanda IamManchanda self-requested a review October 12, 2017 15:14
@@ -178,7 +178,7 @@ class Dropdown extends Positionable {

Keyboard.handleKey(e, 'Dropdown', {
open: function() {
if ($target.is(_this.$anchors)) {
if ($target.is(_this.$anchors) && !$target.is('input')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not only input should be able to get a space without losing the focus. I think we have two solutions:

  • determine all the native elements that should be able to receive space and make a big filter
  • add an option to the dropdown element to prevent the keyboard catching

@ncoden ncoden changed the title Input dropdown fix fix: prevent "space" on input to open dropdown Jan 31, 2018
@ncoden ncoden self-assigned this Jan 31, 2018
@ncoden ncoden added this to the 6.4.4 milestone Jan 31, 2018
@Owlbertz
Copy link
Contributor Author

Good finding with the textareas @ncoden, we should check for button and select as well I guess.

@ncoden
Copy link
Contributor

ncoden commented Jan 31, 2018

Why <button> ? We do expect space or enter on a button to open the dropdown. In the other case, I would simply used .is(':focus') to ignore all focusable anchors.

@Owlbertz
Copy link
Contributor Author

Owlbertz commented Feb 2, 2018

Sorry, I just realized now that I was in a different context. you are correct.

@ncoden
Copy link
Contributor

ncoden commented Feb 2, 2018

See: #10899 (including new feature to control the keyboard on Dropdown), based on this PR.

@ncoden ncoden merged commit 477563d into foundation:develop Feb 10, 2018
ncoden added a commit to ncoden/foundation-sites that referenced this pull request Jun 16, 2018
…r v6.5.0

848e9c0 Added visual test for a Dropdown attached to an input element.
2d736a1 Prevent SPACE from setting focus to the Dropdown if anchor is an input element.
87c3d4f Added unittest for keyboard events for Dropdown.
64e5ede feat: ignore dropdown keyboard event on textarea

Co-Authored-By: Nicolas Coden <[email protected]>
Signed-off-by: Nicolas Coden <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants