Skip to content

Commit

Permalink
Fix submenus not opening on click (#36290)
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines authored and noisysocks committed Nov 10, 2021
1 parent da5023d commit 1c0406c
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions packages/block-library/src/navigation/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,43 @@ function toggleSubmenuOnClick( event ) {
}
}

const submenuButtons = document.querySelectorAll(
'.wp-block-navigation-submenu__toggle'
);

submenuButtons.forEach( function ( button ) {
button.addEventListener( 'click', toggleSubmenuOnClick );
} );

// Close on click outside.
document.addEventListener( 'click', function ( event ) {
const navigationBlocks = document.querySelectorAll(
'.wp-block-navigation'
);
navigationBlocks.forEach( function ( block ) {
if ( ! block.contains( event.target ) ) {
closeSubmenus( block );
}
} );
} );
// Close on focus outside.
document.addEventListener( 'keyup', function ( event ) {
const submenuBlocks = document.querySelectorAll(
'.wp-block-navigation-item.has-child'
);
submenuBlocks.forEach( function ( block ) {
if ( ! block.contains( event.target ) ) {
closeSubmenus( block );
}
} );
} );

// Necessary for some themes such as TT1 Blocks, where
// scripts could be loaded before the body.
window.onload = () =>
window.onload = () => {
MicroModal.init( {
onShow: navigationToggleModal,
onClose: navigationToggleModal,
openClass: 'is-menu-open',
} );

const submenuButtons = document.querySelectorAll(
'.wp-block-navigation-submenu__toggle'
);

submenuButtons.forEach( function ( button ) {
button.addEventListener( 'click', toggleSubmenuOnClick );
} );

// Close on click outside.
document.addEventListener( 'click', function ( event ) {
const navigationBlocks = document.querySelectorAll(
'.wp-block-navigation'
);
navigationBlocks.forEach( function ( block ) {
if ( ! block.contains( event.target ) ) {
closeSubmenus( block );
}
} );
} );
// Close on focus outside.
document.addEventListener( 'keyup', function ( event ) {
const submenuBlocks = document.querySelectorAll(
'.wp-block-navigation-item.has-child'
);
submenuBlocks.forEach( function ( block ) {
if ( ! block.contains( event.target ) ) {
closeSubmenus( block );
}
} );
} );
};

0 comments on commit 1c0406c

Please sign in to comment.