Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop ESC key propagation when closing a submenu #22

Open
mrwweb opened this issue Oct 16, 2024 · 0 comments
Open

Stop ESC key propagation when closing a submenu #22

mrwweb opened this issue Oct 16, 2024 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@mrwweb
Copy link
Owner

mrwweb commented Oct 16, 2024

For cases where a submenu is inside another togglable element, the ESC key should close an open submenu but not close the containing element. Add this so that ESC only closes a parent element if no submenus are open:

function closeOnEscKey( e ) {
	if ( 27 === e.keyCode ) {
		// we're in a submenu item
		if ( null !== e.target.closest( 'ul[aria-hidden="false"]' ) ) {
			currentMenuItem.focus();
			toggleSubmenu( currentMenuItem );
			e.stopPropagation(); // ADDED!
		// we're on a parent item
		} else if ( 'true' === e.target.getAttribute( 'aria-expanded' ) ) {
			toggleSubmenu( currentMenuItem );
			e.stopPropagation(); // ADDED!
		}
	}
}
@mrwweb mrwweb added enhancement New feature or request good first issue Good for newcomers labels Oct 16, 2024
@mrwweb mrwweb added this to the v1.3.0 milestone Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant