You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[MenuButton] Accessibility fixes and allow custom button content (#4093)
* Make FluentMenuButton fully accessible
* Allow providing a render fragment for the button content
* fix bug
* apply pr feedback
* address pr comments
* add a data grid example using HeaderCellAsButtonWithMenu
* move logic up to fluent menu
* undo the menu button focus changes
* undo redundant changes in menu button
* close menus on esc
* fix test
* fix comment, test modules, remove redundant initializer
* remove unused method, add open parameter directly to initialize method
* reinitialize after render
---------
Co-authored-by: Vincent Baaij <vnbaaij@outlook.com>
Co-authored-by: Denis Voituron <dvoituron@outlook.com>
// Return if either the menu or anchor element have not rendered.
56
+
if(!menuElement||!anchorElement){
57
+
return;
58
+
}
59
+
60
+
// We need to handle four cases to be fully accessible:
61
+
// 1. When Tab is pressed on the anchor, focus must be moved to the first focusable element in the menu
62
+
// 2. When Shift+Tab is pressed on any focusable element in the menu, focus must be moved back to the anchor. This will also close the menu.
63
+
// 3. When Tab is pressed on any focusable element in the menu, focus should continue to the next focusable element in the element's root. This will also close the menu.
64
+
// 4. When Escape is pressed on any focusable element in the menu, focus must be moved back to the anchor. This will also close the menu.
65
+
constmenuItemKeydownListener=function(ev){
66
+
if(ev.key==="Tab"||ev.key==="Escape"){
67
+
try{
68
+
ev.preventDefault&&ev.preventDefault();
69
+
ev.stopPropagation&&ev.stopPropagation();
70
+
71
+
if(!ev.shiftKey&&ev.key==="Tab"){
72
+
// When Tab is pressed on a focusable element, we should continue to the next focusable element
73
+
// If this element is a fluent element, we should try to find the next focusable element within the shadow DOM of the fluent element if one exists,
0 commit comments