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

[ISSUE#1881][MAS2.1.2][Keyboard Navigation- Welcome Tab screen] Focus gets trapped on first and last element of the page when user navigates through the page #2001

Merged
merged 16 commits into from
Nov 26, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix getLastDecendants when the last child is disabled
  • Loading branch information
Bill7zz committed Nov 19, 2019
commit 1ff044dc36c2249ca62ee974349d69d77f2e3aa0
11 changes: 6 additions & 5 deletions packages/app/client/src/utils/eventHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ class EventHandlers {
}
}

public static getAllDecendants(node, list = []) {
public static getLastDecendants(node, list = []) {
list = list || [];
if (node.children.length > 0) {
var child = this.getLastChildWithChildren(node);
if (child) {
list.push(child);
this.getAllDecendants(child, list);
this.getLastDecendants(child, list);
}
}
return list;

return [].filter.call(list[list.length - 1].children, element => !element.hasAttribute('disabled'));
}

public static async globalHandles(event: KeyboardEvent): Promise<any> {
Expand Down Expand Up @@ -148,8 +149,8 @@ class EventHandlers {
window.addEventListener('keydown', function(event) {
var KEYCODE_TAB = 9;
var firstElement = document.querySelector('nav').firstElementChild as HTMLElement;
var mainElement = EventHandlers.getAllDecendants(document.querySelector('main'));
var lastElement = mainElement[mainElement.length - 1].children[0] as HTMLElement;
var lastDecendants = EventHandlers.getLastDecendants(document.querySelector('main'));
var lastElement = lastDecendants[lastDecendants.length - 1];

if (event.key === 'Tab' || event.keyCode === KEYCODE_TAB) {
if (event.shiftKey) {
Expand Down