ActionMenu.Anchor should only accept button #5477
Labels
accessibility
bug
Something isn't working
component: ActionMenu
primer-quality
react
staff
Author is a staff member
Description
ActionMenu
has preferred API ofActionMenu.Button
which uses a PrimerButton
and wires it up correctly.However, if you want to customise the anchor, we also provide a
ActionMenu.Anchor
that can be used to give a custom element.While this API is required, it's possible to use it incorrectly.
Spotted in the wild: In this example, the developer is trying to add an "active indicator" on the IconButton by adding an additional element (with aria-label) and positioning it
The above JSX renders inaccessible html:
iconbutton-grouped.mov
Video description:
Proposed Solution
I have 2 suggestions:
ActionMenu.Anchor
is to use anIconButton
, we should create a shortcutActionMenu.IconButton
as a companion toActionMenu.Button
.A blessed shortcut would reduce the chances of implementing it incorrectly.
ActionMenu.Anchor
should validate it's children, if it receives an incorrect element as the root, it should throw a warning and guide the developer to correct usage.My guess is that only button is valid, but we need to validate that assumption. Non-interactive element is definitely a violation. For prior art, we have similar (if not more advanced) checks in Tooltip
Suggested prioritisation:
I have fixed the instance where this was spotted so I am not blocked.
But there are 258 instances of
ActionMenu.Anchor
that need to be audited for their children to decide if this is a widespread bug or a good to haveSteps to reproduce
Navigate to custom anchor story and replace the Anchor with:
Version
v37.5.0
Browser
Chrome
The text was updated successfully, but these errors were encountered: