Skip to content

Commit ccfa79e

Browse files
authored
Editor Menubar Example: Fix tabindex management to ensure only the most recently opened menu is in the page tab sequence (Pull #3309)
Fixes bugs where using a combination of keyboard and mouse interactions caused multiple menu items to be in the page Tab sequence. The following changes ensure that only the most recently opened menu is the only menu item in the page tab sequence regardless of how that menu item was opened or had originally received focus: * Opening a menu via clicking now correctly updates the tabindex values of the menubar items (instead of the submenu items). * Opening a menu via hover now correctly updates the tabindex values of the menubar items (instead of updating nothing due to erroneously passing in a menu rather than an ID). * Opening a menu via Enter, Space, or Arrow Up/Down now updates the tabindex values of the menubar items, since it's possible for the parent menuitem to have received keyboard focus other than through a way that would have already updated the tabindex values (e.g. by pressing on it and dragging off it before releasing).
1 parent 8b05538 commit ccfa79e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

content/patterns/menubar/examples/js/menubar-editor.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ class MenubarEditor {
514514
case ' ':
515515
case 'Enter':
516516
if (this.hasPopup(tgt)) {
517+
// Need to update focus for the parent menu as well as the submenu
518+
this.setFocusToMenuitem(menuId, tgt);
517519
popupMenuId = this.openPopup(tgt);
518520
this.setFocusToFirstMenuitem(popupMenuId);
519521
} else {
@@ -553,6 +555,8 @@ class MenubarEditor {
553555
flag = true;
554556
} else {
555557
if (this.hasPopup(tgt)) {
558+
// Need to update focus for the parent menu as well as the submenu
559+
this.setFocusToMenuitem(menuId, tgt);
556560
popupMenuId = this.openPopup(tgt);
557561
this.setFocusToFirstMenuitem(popupMenuId);
558562
flag = true;
@@ -599,6 +603,8 @@ class MenubarEditor {
599603
flag = true;
600604
} else {
601605
if (this.hasPopup(tgt)) {
606+
// Need to update focus for the parent menu as well as the submenu
607+
this.setFocusToMenuitem(menuId, tgt);
602608
popupMenuId = this.openPopup(tgt);
603609
this.setFocusToLastMenuitem(popupMenuId);
604610
flag = true;
@@ -644,7 +650,9 @@ class MenubarEditor {
644650
if (this.isOpen(tgt)) {
645651
this.closePopup(tgt);
646652
} else {
647-
var menuId = this.openPopup(tgt);
653+
this.openPopup(tgt);
654+
// Need to update focus for the parent menu, not the submenu
655+
var menuId = this.getMenuId(tgt);
648656
this.setFocusToMenuitem(menuId, tgt);
649657
}
650658
} else {
@@ -683,7 +691,8 @@ class MenubarEditor {
683691
var tgt = event.currentTarget;
684692

685693
if (this.isAnyPopupOpen() && this.getMenu(tgt)) {
686-
this.setFocusToMenuitem(this.getMenu(tgt), tgt);
694+
var menuId = this.getMenuId(tgt);
695+
this.setFocusToMenuitem(menuId, tgt);
687696
}
688697
}
689698
}

0 commit comments

Comments
 (0)