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

Create context menu component #110

Merged
merged 17 commits into from
Jan 5, 2024
Merged

Create context menu component #110

merged 17 commits into from
Jan 5, 2024

Conversation

robintown
Copy link
Member

@robintown robintown commented Oct 18, 2023

This component represents a menu that opens when another UI element is right-clicked or long-pressed.

Screencast.from.2023-10-18.00-56-47.webm
Screencast.from.2023-10-18.00-57-04.webm

@robintown robintown requested a review from a team as a code owner October 18, 2023 04:59
@robintown robintown requested review from dbkr and t3chguy and removed request for a team October 18, 2023 04:59
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 18, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 348c9a6
Status: ✅  Deploy successful!
Preview URL: https://010c48e2.compound-web.pages.dev
Branch Preview URL: https://context-menu.compound-web.pages.dev

View logs

This component represents a menu that opens on a button press. Feedback on the API is very welcome - I'm pretty happy with how I managed to condense Radix's tree of menu components into a single component, but we need to make sure that it's intuitive for others too.
This component represents a menu that opens when another UI element is right-clicked or long-pressed.
Base automatically changed from menu to main November 23, 2023 00:14
Copy link
Contributor

@kerryarchibald kerryarchibald left a comment

Choose a reason for hiding this comment

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

Unless I'm missing the key binding, this doesn't seem to be accessible.
Aside from that, I don't feel super confident this should be added to CW. Right click hijacking is pretty broadly considered a dark pattern. I've raised this with the compound team to see if this is something we want to support.

src/components/Menu/ContextMenu.tsx Show resolved Hide resolved
@kerryarchibald
Copy link
Contributor

@robintown as it turns out we already have lots of right click menus in EW Desktop. (I guess right clicking is just not something I do... I had never used them)
They're allowed per platform using BasePlatform.allowOverridingNativeContextMenus
Given that right click menus will be disabled in the browser, all their actions must be available elsewhere. Which I think means we can get away with these menus being inaccessible.
https://github.com/matrix-org/design/issues/231

@t3chguy
Copy link
Member

t3chguy commented Nov 24, 2023

Which I think means we can get away with these menus being inaccessible.

Keep in mind right click context menus are also triggered by Accessibility Technologies using the Menu key or Shift + F10, so they should be accessible if they are presented in the accessibility tree whatsoever.

@robintown
Copy link
Member Author

Re: accessibility - yes, I think we do need to be careful to only provide this component as an extra convenience for pointing device users, and always provide an alternative route for accessing the menu options. Maybe it's enough to document this in the component's doc comment?

@t3chguy
Copy link
Member

t3chguy commented Nov 27, 2023

The current context menus in Element are accessible, given this it is very unlikely we'd want to degrade accessibility by removing those and running 2 implementations is worse than one we maintain ourselves.

@toger5
Copy link

toger5 commented Dec 20, 2023

Not sure this is the best place to comment.
In general I am not sure about the blue/black border around the bottom sheet mobile modal. It looks like it has a border at the tob but not left/right. On the current deployment it also has a border on one of the sides and the top.
I thik we should have the border left/right/top or nowhere. Would that make sense for this PR?

@robintown
Copy link
Member Author

robintown commented Jan 3, 2024

@t3chguy I've taken a second look at the accessibility concerns:

  • The component now sets aria-haspopup="menu" on the trigger. Element Web's implementation doesn't do this, but I believe that attribute is applicable here?
  • Radix's context menu implementation which we're using here does respond to the Menu key, so as long as the trigger is focusable, we appear to be good on the keyboard navigation front.
  • Since the most common use case for context menus is as an additive usability improvement for pointing device users, the extra tab stop often won't be necessary (in the case of Element Web, for instance, it would probably be annoying to add that tab stop to every message, when the 'options' button is right there).
  • But still, it's conceivable that a downstream project might end up with a menu that has no other keyboard-accessible entry point, so I've added hasAccessibleAlternative: boolean as a required prop. The idea is that this will get consumers to at least acknowledge whether they've taken keyboard accessibility into account, and if not, the component can provide a tab stop as a fallback.

How does this solution sound to you? I'd appreciate your review.

@t3chguy
Copy link
Member

t3chguy commented Jan 5, 2024

The component now sets aria-haspopup="menu" on the trigger. Element Web's implementation doesn't do this, but I believe that attribute is applicable here?

Yes, it does. As per MDN:

The value true is the same as menu

image

Agreed otherwise

@robintown robintown merged commit 64e8413 into main Jan 5, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants