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

Kdropdown keyboard navigation #185

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/KDropdownMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
},
},
beforeDestroy() {
window.removeEventListener('keydown', this.handleArrowKeys, true);
window.removeEventListener('keydown', this.handleOpenMenuNavigation, true);
},
methods: {
handleOpen() {
Expand Down Expand Up @@ -134,17 +134,21 @@
let focusedElement = document.activeElement;
let sibling = focusedElement.nextElementSibling;
let prevSibling = focusedElement.previousElementSibling;
// manage rotating through the options
if (event.keyCode == 38 && popoverIsOpen) {

// manage rotating through the options using arrow keys
// UP arrow: .keyCode is depricated and should used only as a fallback
console.log(event.key);
marcellamaki marked this conversation as resolved.
Show resolved Hide resolved
if ((event.key == 'ArrowUp' || event.keyCode == 38) && popoverIsOpen) {
event.preventDefault();
prevSibling
? this.$nextTick(() => prevSibling.focus())
: this.$nextTick(() => lastChild.focus());
} else if (event.keyCode == 40 && popoverIsOpen) {
// DOWN arrow
} else if ((event.key == 'ArrowDown' || event.keyCode == 40) && popoverIsOpen) {
event.preventDefault();
sibling ? this.$nextTick(() => sibling.focus()) : this.$nextTick(() => this.setFocus());
// if a tab key, not an arrow key, close the popover and advance to next item in the tab index
} else if (event.keyCode == 9 && popoverIsOpen) {
// if a TAB key, not an arrow key, close the popover and advance to next item in the tab index
} else if ((event.key == 'Tab' || event.keyCode == 9) && popoverIsOpen) {
this.closePopover();
}
},
Expand Down
7 changes: 6 additions & 1 deletion lib/styles/trackInputModality.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function setUpEventHandlers(disableFocusRingByDefault) {
};

if (disableFocusRingByDefault) {
const css = 'body :focus:not([modality=keyboard]) { outline: none; }';
const css = 'body:not([modality=keyboard]) :focus { outline: none; }';
const head = document.head || document.getElementsByTagName('head')[0];
const style = document.createElement('style');

Expand Down Expand Up @@ -115,7 +115,12 @@ function setUpEventHandlers(disableFocusRingByDefault) {
(hadKeyboardEvent && focusTriggersKeyboardModality(e.target)) ||
(focusSetExplicitly(e.target) && !hadClickEvent)
) {
// both the JS state and the body attribute for keyboard modality
globalThemeState.inputModality = 'keyboard';
document.body.setAttribute('modality', 'keyboard');
} else {
globalThemeState.inputModality = null;
document.body.setAttribute('modality', '');
Comment on lines +120 to +123
Copy link
Contributor

@indirectlylit indirectlylit May 20, 2022

Choose a reason for hiding this comment

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

See learningequality/kolibri#4822 and learningequality/kolibri#4847 for some historical context on how the code got into its current state.

marcellamaki marked this conversation as resolved.
Show resolved Hide resolved
}
},
true
Expand Down