MDL-74701 core: Fix popover elements are focusable even when hidden

This commit is contained in:
Huong Nguyen
2022-06-13 09:45:37 +07:00
parent 22dffcd0c2
commit 01222cbb06
3 changed files with 17 additions and 2 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+15
View File
@@ -129,6 +129,7 @@ define(['jquery', 'core/str', 'core/custom_interaction_events'],
this.menuContainer.attr('aria-expanded', 'false');
this.menuContainer.attr('aria-hidden', 'true');
this.updateButtonAriaLabel();
this.updateFocusItemTabIndex();
this.root.trigger(this.events().menuClosed);
};
@@ -149,6 +150,7 @@ define(['jquery', 'core/str', 'core/custom_interaction_events'],
this.menuContainer.attr('aria-expanded', 'true');
this.menuContainer.attr('aria-hidden', 'false');
this.updateButtonAriaLabel();
this.updateFocusItemTabIndex();
// Resolve the promises to allow the handlers to be added
// to the DOM, if they have been requested.
this.promises.closeHandlers.resolve();
@@ -392,5 +394,18 @@ define(['jquery', 'core/str', 'core/custom_interaction_events'],
}.bind(this));
};
/**
* Set the appropriate tabindex attribute on the popover toggle.
*
* @method updateFocusItemTabIndex
*/
PopoverRegionController.prototype.updateFocusItemTabIndex = function() {
if (this.isMenuOpen()) {
this.menuContainer.find(SELECTORS.CAN_RECEIVE_FOCUS).removeAttr('tabindex');
} else {
this.menuContainer.find(SELECTORS.CAN_RECEIVE_FOCUS).attr('tabindex', '-1');
}
};
return PopoverRegionController;
});