Close .vector-menu-dropdown menus in modern Vector beforeunload

Per T295085, because of the checkbox hack, these menu would stay open
when navigating back to a page.

Bug: T295085
Change-Id: Ief9523030384b4bcaa00379988e2042b4d177dcc
This commit is contained in:
Nicholas Ray 2021-12-13 17:24:44 -07:00
parent 326a9db5e3
commit 3187fa41ad
1 changed files with 14 additions and 0 deletions

View File

@ -33,6 +33,19 @@ function bindToggleOnSpaceEnter() {
} );
}
/**
* T295085: Close all dropdown menus when page is unloaded to prevent them from
* being open when navigating back to a page.
*/
function bindCloseOnUnload() {
addEventListener( 'beforeunload', function () {
document.querySelectorAll( CHECKBOX_HACK_CHECKBOX_SELECTOR + ':checked' )
.forEach( function ( checkbox ) {
/** @type {HTMLInputElement} */ ( checkbox ).checked = false;
} );
} );
}
/**
* Make sure that clicking outside a menu closes it.
*/
@ -99,4 +112,5 @@ mw.hook( 'util.addPortletLink' ).add( addPortletLinkHandler );
module.exports = function dropdownMenus() {
closeDropdownsOnClickOutside();
bindToggleOnSpaceEnter();
bindCloseOnUnload();
};