Skip to content

Introduce Menu component (aka DropdownMenu v2) #50459

Closed

Description

@ciampo

Related to #49271

We would like to build a mode modular, accessible, and feature-rich (eg. with support for sub-menus) version of the DropdownMenu component.

Given how tricky it can be to implement this feature in an accessible and usable way, we're going to leverage ariakit and its Menu component. We initially tested Radix UI but found some blockers.

Choosing an API approach

After some initial discussion, we've landed on an approach:

  • Keep ariakit as an internal implementation detail as much as possible
  • Expose as few props as needed
  • Expose low-level, granular components, to allow for greater flexibility
  • Consider adding as many guidelines, examples, and any other tools to help consumers use the component correctly.

Next steps:

This may close #18537

Activity

  1. self-assigned this
    on May 9, 2023
  2. added
    [Package] Components
    on May 9, 2023
  3. alexstine commented on May 9, 2023

    @alexstine
    Contributor

    Please let me know when ready for accessibility testing. Added a couple required checks above to ensure it is not missed before publishing the package.

  4. ciampo commented on May 23, 2023

    @ciampo
    ContributorAuthor

    Hey all, an experimental version of the new DropdownMenu component has been added to the repository:

    These are still very early days, but it is a great time to gather some early feedback on all aspects:

    In order to keep this issue as a tracking issue, it would be great if y'all could open separate issues — we can link them all in this issue's description.

    In the upcoming days, I'm going to start testing the new component in the editor, in order to spot any issues and missing features, and I'll start work on adding support for using the component with SlotFill.

    Thanks!

  5. jameskoster commented on May 23, 2023

    @jameskoster
    Contributor

    That's looking great already ✨

    Seems like the visual design is based on some rough explorations I worked on in Figma. Here's the link to that in case anyone else would like to riff on the appearance.

  6. alexstine commented on May 23, 2023

    @alexstine
    Contributor

    @ciampo This seems to be testing well on Windows. Would be nice to get a Mac review. CC: @afercia .

  7. SaxonF commented on May 24, 2023

    @SaxonF
    Contributor

    Nice work!

    (Edit by @ciampo : moved the feedback to a separate issue: #50910)

  8. andrewhayward commented on May 24, 2023

    @andrewhayward
    Contributor

    Was playing around with the Storybook example, and I noticed that pressing escape collapses the entire menu. This is fine at the top level, but submenus should collapse up to their parent. I checked the underlying Radix UI component, and it behaves the same, so I'm guessing it's a problem there rather than with this. Will need to raise a ticket on that project to resolve.

  9. andrewhayward commented on May 25, 2023

    @andrewhayward
    Contributor

    Will need to raise a ticket on that project to resolve.

    Looks like a ticket was already raised, and closed as "won't fix". Not a blocker, by any stretch, but probably worth making note of.

  10. alexstine commented on May 25, 2023

    @alexstine
    Contributor

    I would prefer the escape to take me out of submenus before closing the entire menu especially if you were multiple levels deep. The argument about Mac OS in that issue is invalid for Windows. Opening a Windows context menu, then submenu, and pressing escape will focus the submenu trigger.

    I am not sure it should be a blocker for the first implementation but I am not a fan of how the contributors dismissed that issue. This could come back to haunt us later. It's the risk you take with 3rd-party.

  11. ciampo commented on May 25, 2023

    @ciampo
    ContributorAuthor

    It's the risk you take with 3rd-party.

    Yup, and it is a calculated one. Using a well-known and actively maintained third-party library allowed us to iterate on this otherwise fairly complex component quite quickly and with very good results. We can definitely expect situations like this one, but the hope is that there won't be many and that the trade-off will be advantageous for the project.

  12. andrewhayward commented on May 25, 2023

    @andrewhayward
    Contributor

    I think we've got a few options at this point:

    1. Leave things as they are, and accept the situation for what it is.
    2. Work with the upstream project, if not to change the current behaviour (evidently that's unlikely to happen), then at least to contribute something that would give us more flexibility to do things to our preference.
    3. Fork the upstream project and make adjustments.
    4. Make adjustments within our component. Given that we're not exposing any upstream primitives, we can override specific event handlers without causing complexity for component consumers.

    I'm not a huge fan of 1, but it might be sufficient for the immediate term to get something working. 2 runs the risk of being rejected, at which point we'd be back to this conversation. 3 is (from my perspective anyway) a total non-starter. And 4 is arguably something of a hack, but could probably be done relatively cleanly, at least from a code perspective.

  13. mirka commented on May 25, 2023

    @mirka
    Member

    Leave things as they are, and accept the situation for what it is

    To be honest, I was kind of persuaded by all the reasoning that was given in closing the upstream issue as wontfix. The left arrow key will always return you to the closest parent, whereas Escape is the only key that will escape you out completely no matter what. (I'm imagining a situation where the focus is in a submenu nested two or more levels deep.)

    So given that there is a functional advantage, plus the ARIA APG being ambiguous, plus two major reference implementations (Windows and macOS) diverging on this, I don't see the current Escape behavior as a clearly bad thing we should fix.

  14. alexstine commented on May 25, 2023

    @alexstine
    Contributor

    Yes, I think it is likely fine the way it is and should not be blocked. I just wanted to highlight the fact that if we do go down the road of implementing more 3rd-party components, these types of issues might not be so clear-cut. There is also a reason why people with disabilities continue to keep Windows at the top of the operating system list. Anyone here who has tried to use Mac Voiceover I am sure understands why.

    Anyway, super excited for this to continue. This will be a nice submenu implementation that very closely mocks Google Drive and now Gmail context menus.

    Thanks for the work here.

  15. 4 remaining items

  16. ciampo commented on Jun 16, 2023

    @ciampo
    ContributorAuthor

    @ciampo are you thinking this may make it into 6.3 (re #51400)?

    Hey Rich, I've just posted an update directly on the PR. The TL;DR is that we've hit a bit of a wall around how the DropdownMenu enforces its "modality" and how it interacts with other Popover-based components.

    I'll continue exploring more solutions in the next days, but as of today I'm not sure we'll be able to land #51400 before the 6.3 release.

    In the meantime, it would be great to start getting some feedback about that PR anyway!

  17. added
    [Type] Enhancement
    on Jul 20, 2023
  18. ciampo commented on Sep 29, 2023

    @ciampo
    ContributorAuthor

    Quick update: after #51400 surfaced a few critical limitations with using radix-ui for the new DropdownMenu component in the block editor, I tested ariakit as an alternative with encouraging results.

    In the upcoming days, I will go ahead and try to put together a version of DropdownMenu based off ariakit, and then I'll try it again in the block settings dropdown — hopefully we should be on a good path 🤞

    I will also update this issue's TODOs to better reflect the new plan of action.

  19. afercia commented on Dec 6, 2023

    @afercia
    Contributor

    I'd like to propose to consider to make the new dropdown component handle automatically the case where the passed items are only 1 item. See #56792 for the current droopdown.
    We should avoid the component to render a dropdown that contains only one item as that's not a great UX. Could this be handled automatically? Cc @jorgefilipecosta

  20. andrewhayward commented on Dec 6, 2023

    @andrewhayward
    Contributor

    We should avoid the component to render a dropdown that contains only one item as that's not a great UX. Could this be handled automatically?

    A couple of thoughts...
    Two rows of action buttons, side by side. The first set shows ellipsis action menus, one being open with a single 'edit' item. The second shows 'edit' icons in place of two of the action menus, with the third menu remaining.

    First, I'm not sure how we could reasonably translate any generic menu item into a button in an automated way, given the number of variables involved. In the example above, we've going from a menu item with text and no icon, to an action button with an icon but no text. Not saying it's not possible, but certainly not straightforward. The API for doing so could get quite complex quite quickly.

    Second, while I agree that we should ideally avoid action menus with one item, there's also an argument for consistency. There's a lot out there on macro consistency (including SC 3.2.3 and SC 3.2.4), but not so much on micro consistency. So this is isn't a suggestion either way, but we should definitely think about whether (in cases like this specifically) it's actually more confusing to have a mix of different modalities.

  21. youknowriad commented on Dec 6, 2023

    @youknowriad
    Contributor

    Just a comment as a regular user. If I have in the same table, two rows and maybe one row is editable and the other not. which would mean, for one row, you have two items in the "more menu" and for the other only one. I'd definitely favor consistency over having the button in different places across the two rows. So IMO, it's not something to be handled at the DropdownMenu component level.

  22. jameskoster commented on Dec 6, 2023

    @jameskoster
    Contributor

    FWIW it should be very rare for the ellipsis menu in data views to only contain a single action. The idea is for it to also contain quick edit actions like 'rename', 'view revisions', 'make sticky'... essentially everything you can do in the 'quick edit' experience in wp-admin. An older mockup for pages:

    Screenshot 2023-12-06 at 13 49 11
  23. added
    [Type] Tracking Issue
    on Dec 22, 2023
  24. jorgefilipecosta commented on Jan 16, 2024

    @jorgefilipecosta
    Member

    I'd like to propose to consider to make the new dropdown component handle automatically the case where the passed items are only 1 item. See #56792 for the current droopdown. We should avoid the component to render a dropdown that contains only one item as that's not a great UX. Could this be handled automatically? Cc @jorgefilipecosta

    I guess automatically avoiding rendering dropdown menus with only one item is not feasible. It depends on what triggers the dropdown menu to open. It may be a simple button, it may be a small toolbar button, etc. But when using dropdown menus if the possibility of having only one item exists we should add the logic to avoid that.

  25. changed the title [-]DropdownMenu: support nested menus[/-] [+]DropdownMenu v2[/+] on Jul 24, 2024
  26. changed the title [-]DropdownMenu v2[/-] [+]DropdownMenu v2 (aka Menu)[/+] on Nov 1, 2024
  27. changed the title [-]DropdownMenu v2 (aka Menu)[/-] [+]Introduce Menu component (aka DropdownMenu v2)[/+] on Nov 26, 2024
  28. added
    [Type] New API
    on Dec 5, 2024
  29. ciampo commented on Sep 3, 2026

    @ciampo
    ContributorAuthor

    Closing since we're now focused on the @wordpress/ui package, which offers a new Menu component.

    The experimental Ariakit-based Menu component in the @wordpress/components package will be gradually replaced by the new component, and eventually deprecated / removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[Package] Components[Type] Enhancement[Type] New API[Type] Tracking Issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions