mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-24 07:43:47 +00:00
Make dropdown menus toggle with enter key
Bug: T291096 Change-Id: Ia5d1a33aa04dab09f1454ade4816fdb9d48f1eca
This commit is contained in:
parent
ae28c427d6
commit
876d3ddf39
|
@ -2,7 +2,7 @@
|
|||
See @typedef MenuDefinition
|
||||
}}
|
||||
{{! `role` is unnecessary but kept to support selectors in any gadgets or user styles. }}
|
||||
<nav id="{{id}}"{{#class}} class="{{.}}"{{/class}} aria-labelledby="{{id}}-label" role="navigation" {{{html-tooltip}}}
|
||||
<nav id="{{id}}" class="{{#class}}{{.}} {{/class}}{{#is-dropdown}}vector-menu-dropdown{{/is-dropdown}}" aria-labelledby="{{id}}-label" role="navigation" {{{html-tooltip}}}
|
||||
{{{html-user-language-attributes}}}>
|
||||
{{#is-dropdown}}
|
||||
<input type="checkbox"
|
||||
|
|
|
@ -1,3 +1,34 @@
|
|||
/** @interface CheckboxHack */
|
||||
|
||||
var
|
||||
checkboxHack = /** @type {CheckboxHack} */ require( /** @type {string} */( 'mediawiki.page.ready' ) ).checkboxHack,
|
||||
CHECKBOX_HACK_CONTAINER_SELECTOR = '.vector-menu-dropdown',
|
||||
CHECKBOX_HACK_CHECKBOX_SELECTOR = '.vector-menu-checkbox',
|
||||
CHECKBOX_HACK_BUTTON_SELECTOR = '.vector-menu-checkbox',
|
||||
CHECKBOX_HACK_TARGET_SELECTOR = '.vector-menu-content';
|
||||
|
||||
/**
|
||||
* Add the ability for users to toggle dropdown menus using the enter key (as
|
||||
* well as space) using core's checkboxHack.
|
||||
*/
|
||||
function bindToggleOnSpaceEnter() {
|
||||
// Search for all dropdown containers using the CHECKBOX_HACK_CONTAINER_SELECTOR.
|
||||
var containers = document.querySelectorAll( CHECKBOX_HACK_CONTAINER_SELECTOR );
|
||||
|
||||
Array.prototype.forEach.call( containers, function ( container ) {
|
||||
var
|
||||
checkbox = container.querySelector( CHECKBOX_HACK_CHECKBOX_SELECTOR ),
|
||||
button = container.querySelector( CHECKBOX_HACK_BUTTON_SELECTOR ),
|
||||
target = container.querySelector( CHECKBOX_HACK_TARGET_SELECTOR );
|
||||
|
||||
if ( !( checkbox && button && target ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkboxHack.bindToggleOnSpaceEnter( checkbox, button );
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that clicking outside a menu closes it.
|
||||
*/
|
||||
|
@ -63,4 +94,5 @@ mw.hook( 'util.addPortletLink' ).add( addPortletLinkHandler );
|
|||
|
||||
module.exports = function dropdownMenus() {
|
||||
closeDropdownsOnClickOutside();
|
||||
bindToggleOnSpaceEnter();
|
||||
};
|
||||
|
|
|
@ -47,7 +47,6 @@ function main( window ) {
|
|||
enableCssAnimations( window.document );
|
||||
collapsibleTabs.init();
|
||||
sidebar.init( window );
|
||||
dropdownMenus();
|
||||
vector.init();
|
||||
initSearchLoader( document );
|
||||
// Initialize the search toggle for the main header only. The sticky header
|
||||
|
@ -55,6 +54,10 @@ function main( window ) {
|
|||
searchToggle( document.querySelector( '.mw-header .search-toggle' ) );
|
||||
languageButton();
|
||||
stickyHeader();
|
||||
// dropdownMenus should be placed afer sticky header is initialized in order to
|
||||
// bind the correct event handlers to the sticky header dropdown menus (e.g.
|
||||
// user menu).
|
||||
dropdownMenus();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue