-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[WIP] Navigation Menu: dropdown activation mode #18445
Conversation
Question: How are we going to deal when the menu has defined the activation mode with In some way, it's related to the possibility to render an item with a not-anchor element. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -73,7 +74,7 @@ function NavigationMenu( { | |||
return null; | |||
} | |||
|
|||
return pages.map( ( { title, type, link: url, id } ) => ( | |||
return pages.map( ( { title, type, link: url, id, menuEventActivation } ) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering whether menuEventActivation
would be clearer as dropdownActivationEvent
. At the least swapping Event
and Activation
should happen to make the "thing" we are describing (ie: the event) is clearer (ie: menuActivationEvent
).
( | ||
( $has_sub_items && ! $on_hover_mode ) | ||
? ( | ||
'<input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need some ARIA roles here such as aria-pressed
and aria-expanded
.
class="wp-block-navigation-menu-item__toggle-handler" | ||
type="checkbox" | ||
>' . | ||
'<label |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps take a look at Bootstrap's "Dropdown" implementation for a11y guidance here.
selected={ selected } | ||
onChange={ onChange } | ||
label={ __( 'Dropdown menu activation' ) } | ||
help={ __( 'Select the way of how the dropdown menu will be activated.' ) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Select the way of how the dropdown menu will be activated
Could be phrased as
Choose the way dropdown menus will be activated
&:hover, | ||
&:focus-within { | ||
cursor: pointer; | ||
z-index: 99999; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this super high value about? 😄
// Submenu Display | ||
&:hover > ul, | ||
&:focus-within > ul, | ||
& ul:hover, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these needed? If the ul
is within the li
then the :hover
on the li
should sustain the hover effect.
|
||
&.is-activated-by-click li { | ||
input.wp-block-navigation-menu-item__toggle-handler { | ||
display: none; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will make the control impossible to access for assistive tech. Better to use the VisuallyHidden
component or a CSS solution to hide visually but retain access for assistive tech:
See also https://wordpress.slack.com/archives/C02QB2JS7/p1573637389298100
display: none; | ||
} | ||
|
||
label.wp-block-navigation-menu-item__toggle-for { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd avoid qualifying with label
unless it is required for specificity. Otherwise we're increasing the specificity for no reason which I would tend to avoid at all costs.
Ditto for input.
above.
I wanted to dig a little in why this is being added and how perhaps we could simplify. First, is this going to be seen by everyone or something you can extend? If everyone, I would suggest considering having a toggle and reducing a little to what is the default. Maybe by having a top settings section: I do wonder though how this works with sub-menus as the parent is a link. Perhaps I am missing some background on this as it would be great to know. |
What's the status on this one? |
In #22824 (comment) we are discussing a hamburger menu button. For this to work and be accessible, we can't use the checkbox hack, we have to have some JS output. Potentially that same JS could be used to toggle open submenus on click. |
@jasmussen Do we still want to pursue this? Having the option to toggle based on hover/focus vs click could be useful. How do you see this working with the hamburger you're discussing in relation to mobile? @retrofox are you likely to be working on this anytime soon? |
👋, Dave. I'm not sure whether I'll be able to look into this in the short term. I'm going to take a look when I have the chance. I think it depends on the answer to - Do we still want to pursue this? |
I think we want to eventually revisit this. However I also think it's more complicated than it seems. As an exapmle, if the primary menu item links to /products, but also opens a dropdown of subpages, how do you get to /products, if clicking on the menu item just opens the dropdown? Options:
It's solvable, we should solve it. But it's less obvious than a toggle, I would say. |
As a sidenote, in the twentytwentyone theme we did something similar, allowing both hover & click events. |
Thanks for sharing that, @aristath, I wasn't aware. Is this the behavior to which you are referring? I.e. as you say, both hover and click at the same time? If yes, that does seem to be a variant of the first option I suggested, a split button. I do appreciate that it can become a toggle like you suggest, but I don't personally find the behavior entirely intuitive or obvious. That said, I'd be super happy to help polish a PR that landed that exact behavior as a baseline, and then we could always go from there. |
Yes. The implementation adds a split button, and initially we had submenus only expand on click. But there were a few complaints from people too used to the on-hover action, so the combo behavior was a compromise between the 2. Using a split button opens up a lot of possibilities... It can work on hover, on click or both, and styling-wise there's a lot we can do 👍 |
I believe this has already been addressed. Version 14.2.0 of the editor has this option for the Navigation Block: I am going to close this but please feel free to reopen if necessary, @retrofox. Thank you! |
Description
This PR implements the ability to set the event which opens the dropdown menu in the front-end, adding a section in the inspector control.
Fixes #18395
Notes:
onClick
should be handled also with js since it isn't possible with just CSS.How has this been tested?
Once these changes are applied, you should be able to see the
Dropdown Menu Activation
block in the inspector control:It allows changing the behavior of how the dropdown menu shows in the front-end through of the selected event:
hover
orclick
.Types of changes
Checklist: