Skip to content

[DropdownMenu] Add aria-labelledby to follow spec #692

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

Merged
merged 4 commits into from
Jun 10, 2021

Conversation

jjenzz
Copy link
Contributor

@jjenzz jjenzz commented Jun 8, 2021

This is the first PR of a few that I will be raising with various accessibility improvements.

  • Adds aria-labelledby to MenuSubContent and the root DropdownMenuContent. Annoyingly the label isn't being read aloud in NVDA but I will look into this separately.

  • Creates a new DropdownMenuRoot part because there are a bunch of attributes on the root content that are not required in the sub dropdown menus. This was also needed because the root aria-labelledby would override the submenu aria-labelledby in MenuSubContent if this attribute was added to both types within the DropdownMenu composition which resulted in incorrect ids for submenus (they would be pointing at the DropdownMenuTrigger id).

  • Updates aria-expanded for sub menu triggers to follow WAI-ARIA spec

    image
    image

@@ -41,7 +41,7 @@ const SUB_CLOSE_KEYS: Record<Direction, string[]> = {

const MENU_NAME = 'Menu';

type MenuContextValue = {
type MenuRootContextValue = {
isSubmenu: false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would there be any value in updating these to isRootMenu instead for consistency?

One advantage I can think of, which I noted a few times whilst reviewing the PRs but never commented on is that in ternaries root would come before sub which to me is more readable or makes more sense to my brain 😀

But again at the time before I didn't think that was enough of a reason to comment on it or ask for a change.
Perhaps now it is?

Copy link
Contributor Author

@jjenzz jjenzz Jun 10, 2021

Choose a reason for hiding this comment

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

Would there be any value in updating these to isRootMenu instead for consistency?

I don't think so. The intent is different here. In DropdownMenu we need to know if it is the root menu to do root menu specific things related to the new trigger part.

In Menu we want to know if they are in a submenu in order to render the submenu content part. I don't really think we need to be consistent, they're different requirements.

We're probably bikeshedding a bit but happy to change it if we think the consistency is preferred.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough, I don't think it matters much what you test for as in the end it's the same result but I can see why we'd want to keep it closer to what we're catering for. Looking at it, it would reverse some ternaries in the way I mentioned but more of them would then be the wrong way, so you're probably right 😀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you would prefer root parts to render before sub parts in the ternary then I could always do !context.isSubmenu? 😏

Copy link
Contributor

@benoitgrelard benoitgrelard left a comment

Choose a reason for hiding this comment

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

I'm happy with this! ♥️
Good to go for me 👍

@benoitgrelard benoitgrelard merged commit 5b53d03 into submenu Jun 10, 2021
@benoitgrelard benoitgrelard deleted the submenu-dropdown-menu-ids branch June 10, 2021 13:00
benoitgrelard added a commit that referenced this pull request Jun 15, 2021
* [Menu] Add submenu primitives (#627)

Co-authored-by: Jenna Smith <[email protected]>

* [Menu] Provide predictable typeahead scoping (#662)

* Scope typeahead via collection

* Exclude only on typeahead space key

* Simplify typeahead

* Prevent continuous `updateSearch` call

* Inline `onExclusiveKeyDown` functionality

* Clear search buffer when leaving

* Move `MenuSubTrigger` code below `MenuContent`

* `isTypingAhead` conditional clarity

* [ContextMenu][DropdownMenu] Integrate new submenu parts (#629)

* [ContextMenu][DropdownMenu] Add `TriggerItem` part (#683)

* [ContextMenu][DropdownMenu] Don't close on sub trigger pointer down (#684)

Co-authored-by: Jenna Smith <[email protected]>

* [ContextMenu][DropdownMenu] Add pointer grace for navigation to sub-menus (#688)

* [ContextMenu][DropdownMenu] delay sub trigger open via pointer

* Add pointer area grace

* Use clientX/Y rather than pageX/Y because getBoundingClientRect doesn't include scroll

* Update DropdownMenu.stories.tsx

* feedback

* onItemEnter

* Update Menu.tsx

* more explicit open timer ref

* Remove content rect caching

* Move MenuItemImpl down (#689)

* [DropdownMenu] Add `aria-labelledby` to follow spec (#692)

* Add `aria-labelledby`

* Follow `aria-expanded` spec for submenu triggers

* Updates based on feedback

* Rename root context type

* [ContextMenu] Bring inline with `DropdownMenu` changes (#693)

* Remove `ArrowUp` to open (#702)

* [DropdownMenu] Enable `onEntryFocus` for root menu (#694)

* Focus first item when all content types open for keyboard users

* Initial feedback addressed

* Add `pointerdown` to keyboard user logic

* Remove capture

* Re-apply capture events with comment

* [ContextMenu][DropdownMenu] Improve pointer grace (#691)

* Share grace timer ref in content

* Align pointer behaviour closer with native

* Simplify base story for easier test

* Remove export of private func

* Tidy from feedback

* Minor naming adjustment

* Apply `useCallback`

Co-authored-by: Andy Hook <[email protected]>

* [ContextMenu][DropdownMenu] Fix menu focus after pointer interaction (#707)

* Fix menu focus after pointer interaction

* Add explainer

* [Menu] Remove `onPointerDownOutside` on sub (#708)

* [ContextMenu][DropdownMenu] Improve touch/mouse handling separation (#709)

* [ContextMenu][DropdownMenu] Improve touch/mouse handling separation

* Feedback

* [DropdownMenu][ContextMenu] Unwind all nested menus with ESC

* [Menu] Tidy `handleSelect` binding

* [Menu] Remove callbackRef in handleSelect

* [Menu] onSelect optional chain

Co-authored-by: Jenna Smith <[email protected]>
Co-authored-by: Benoît Grélard <[email protected]>
Co-authored-by: Jenna Smith <[email protected]>
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.

3 participants