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(dropdown): restore space bar and enter key item selection #3926

Merged
Next Next commit
fix(dropdown): select item on space/enter keypress
  • Loading branch information
emyarod committed Sep 6, 2019
commit 09aefa7c114ab4e836d559eba567159615f4e4b9
15 changes: 15 additions & 0 deletions packages/components/src/components/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ class Dropdown extends mixin(
this.navigate(direction);
event.preventDefault(); // Prevents up/down keys from scrolling container
} else {
// get selected item
// in v10.0, the anchor elements fire click events on Enter keypress when a dropdown item is selected
// in v10.6 (#3586), focus is no longer placed on the dropdown items and is instead kept fixed on the ul menu
// so we need to manually call getCurrentNavigation and select the item
const item = this.getCurrentNavigation();
if (
item &&
isOpen &&
(event.which === 13 || event.which === 32) &&
!this.element.ownerDocument.activeElement.matches(
this.options.selectorItem
)
) {
this.select(item);
}
this._toggle(event);
}
}
Expand Down