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

Rewrite menu from scratch to support mobile sized screens and keyboard controls #175

Merged
merged 8 commits into from
Oct 13, 2020
Prev Previous commit
Next Next commit
Add home/end key control
  • Loading branch information
Giwayume committed Oct 12, 2020
commit bedc3f579ad956c943eaaad91c0ce85fb37bc1fc
48 changes: 38 additions & 10 deletions src/js/core/gui/gui-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ class GUI_menu_class {
activeElement.click();
}
}
else if (event.key === 'Home') {
menuParent.querySelector(`[data-index="0"]`).focus();
}
else if (event.key === 'End') {
menuParent.querySelector(`[data-index="${ menuParent.querySelectorAll('[data-index]').length - 1 }"]`).focus();
}
else if ([' ', 'Enter'].includes(event.key)) {
event.preventDefault();
activeElement.click();
Expand Down Expand Up @@ -179,20 +185,42 @@ class GUI_menu_class {
nextLink.focus();
}
else if (['Right', 'ArrowRight'].includes(event.key)) {
const menuBarLinkIndex = parseInt(this.dropdownStack[0].opener.getAttribute('data-index'), 10) || 0;
let nextLink = this.menuBarNode.querySelector(`[data-index="${ menuBarLinkIndex + 1 }"]`);
if (!nextLink) {
nextLink = this.menuBarNode.querySelector(`[data-index="0"]`);
if (activeElement.getAttribute('aria-haspopup') === 'true') {
activeElement.click();
}
else if (this.dropdownStack.length > 1) {
const opener = this.dropdownStack[linkLevel - 1].opener;
opener.click();
opener.focus();
}
else {
const menuBarLinkIndex = parseInt(this.dropdownStack[0].opener.getAttribute('data-index'), 10) || 0;
let nextLink = this.menuBarNode.querySelector(`[data-index="${ menuBarLinkIndex + 1 }"]`);
if (!nextLink) {
nextLink = this.menuBarNode.querySelector(`[data-index="0"]`);
}
nextLink.click();
}
nextLink.click();
}
else if (['Left', 'ArrowLeft'].includes(event.key)) {
const menuBarLinkIndex = parseInt(this.dropdownStack[0].opener.getAttribute('data-index'), 10) || 0;
let previousLink = this.menuBarNode.querySelector(`[data-index="${ menuBarLinkIndex - 1 }"]`);
if (!previousLink) {
previousLink = this.menuBarNode.querySelector(`[data-index="${ this.menuBarNode.querySelectorAll('[data-index]').length - 1 }"]`);
if (this.dropdownStack.length > 1) {
const opener = this.dropdownStack[linkLevel - 1].opener;
opener.click();
opener.focus();
} else {
const menuBarLinkIndex = parseInt(this.dropdownStack[0].opener.getAttribute('data-index'), 10) || 0;
let previousLink = this.menuBarNode.querySelector(`[data-index="${ menuBarLinkIndex - 1 }"]`);
if (!previousLink) {
previousLink = this.menuBarNode.querySelector(`[data-index="${ this.menuBarNode.querySelectorAll('[data-index]').length - 1 }"]`);
}
previousLink.click();
}
previousLink.click();
}
else if (event.key === 'Home') {
menuParent.querySelector(`[data-index="0"]`).focus();
}
else if (event.key === 'End') {
menuParent.querySelector(`[data-index="${ this.dropdownStack[linkLevel - 1].children.length - 1 }"]`).focus();
}
else if ([' ', 'Enter'].includes(event.key)) {
event.preventDefault();
Expand Down