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

[WIP] Navigation Menu: dropdown activation mode #18445

Closed
wants to merge 6 commits into from

Conversation

retrofox
Copy link
Contributor

@retrofox retrofox commented Nov 11, 2019

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:

  • I'm not totally unconfident about the text defined on this block. Feedback is more than welcome!
  • 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:

Screen Shot 2019-11-11 at 4 49 17 PM

It allows changing the behavior of how the dropdown menu shows in the front-end through of the selected event: hover or click.

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR. .

@retrofox retrofox added [Type] Enhancement A suggestion for improvement. Needs Design Feedback Needs general design feedback. [Feature] List View Menu item in the top toolbar to select blocks from a list of links. [Block] Navigation Affects the Navigation Block labels Nov 11, 2019
@retrofox retrofox requested review from noisysocks and removed request for ajitbohra November 11, 2019 19:56
@retrofox
Copy link
Contributor Author

retrofox commented Nov 12, 2019

Question: How are we going to deal when the menu has defined the activation mode with click, and the item has a link?

In some way, it's related to the possibility to render an item with a not-anchor element.

@getdave getdave changed the title [WIP] Navigation Menu: activation mode [WIP] Navigation Menu: dropdown activation mode Nov 13, 2019
Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work here. A tricky problem.

A few a11y concerns and minor CSS implementation points.

Also when testing hover mode with TwentyTwenty I saw this

Screen Shot 2019-11-13 at 09 35 16

@@ -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 } ) => (
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.' ) }
Copy link
Contributor

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;
Copy link
Contributor

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,
Copy link
Contributor

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;
Copy link
Contributor

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 {
Copy link
Contributor

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.

@karmatosed
Copy link
Member

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:

Frame 7

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.

@karmatosed karmatosed removed the Needs Design Feedback Needs general design feedback. label Jan 22, 2020
@mtias
Copy link
Member

mtias commented Mar 10, 2020

What's the status on this one?

@talldan talldan removed the [Feature] List View Menu item in the top toolbar to select blocks from a list of links. label Jun 11, 2020
Base automatically changed from master to trunk March 1, 2021 15:42
@jasmussen
Copy link
Contributor

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.

@getdave
Copy link
Contributor

getdave commented Apr 7, 2021

@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?

@retrofox
Copy link
Contributor Author

retrofox commented Apr 7, 2021

@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?

@jasmussen
Copy link
Contributor

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?

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:

  • You can't open the dropdown by clicking the menu item, you have to click the chevron to the right of it. Consistent, but probably not obvious.
  • You can only visit /products if you click twice, once to open, another to visit. Probably also not discoverable, or accessible.
  • The main menu item becomes completely inert, and the /product link is duplicated inside. Could work well, likely needs some ability to customize the duplicate label, such as "See all", though potentially we could use the Menu Description field for this.
  • The menu item becomes impossible to visit entirely. Not a good solution.
  • A new menu item is created, "Dropdown menu", which serves only to open the dropdown on click.

It's solvable, we should solve it. But it's less obvious than a toggle, I would say.

@aristath
Copy link
Member

aristath commented Apr 8, 2021

As a sidenote, in the twentytwentyone theme we did something similar, allowing both hover & click events.
It was a bit tricky getting it right, but I feel it was the best of both worlds, as it allows most scenarios and is as accessible as a navigation can possibly be.
To accomplish that we inject a <button> (the caret) in menu items (see markup for the button here), and then there's a script that takes care of the rest: https://github.com/WordPress/twentytwentyone/blob/trunk/assets/js/primary-navigation.js
I assume we can do the same here, and it's not a binary option (click or hover), in order to be accessible we need to take into account all interaction paths.
On a personal note I love click and strongly dislike hover... but the above implementation proved to be satisfying to all.

@jasmussen
Copy link
Contributor

Thanks for sharing that, @aristath, I wasn't aware. Is this the behavior to which you are referring?

tt1

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.

@aristath
Copy link
Member

aristath commented Apr 8, 2021

Is this the behavior to which you are referring?

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.
It works great with keyboard navigation though, which was a big priority.

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 👍

@mrfoxtalbot
Copy link

I believe this has already been addressed. Version 14.2.0 of the editor has this option for the Navigation Block:

Screen Shot on 2022-10-03 at 12:15:58

I am going to close this but please feel free to reopen if necessary, @retrofox. Thank you!

@mrfoxtalbot mrfoxtalbot closed this Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Navigation Block: Allow configuring behaviour of dropdowns.
8 participants