docs(menu): expand accessibility guidance for AI codegen#4072
Conversation
Restructure Menu accessibility docs to match the Dialog/FormField pattern with minimum structure, built-in behaviors, requirements, and anti-patterns for codegen. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Workday/canvas-kit
|
||||||||||||||||||||||||||||||||||||||||
| Project |
Workday/canvas-kit
|
| Branch Review |
purva-a11y-doc-update-menu
|
| Run status |
|
| Run duration | 02m 31s |
| Commit |
|
| Committer | purvas12 |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
17
|
|
|
0
|
|
|
809
|
| View all changes introduced in this branch ↗︎ | |
UI Coverage
19.52%
|
|
|---|---|
|
|
1540
|
|
|
371
|
Accessibility
99.44%
|
|
|---|---|
|
|
5 critical
5 serious
0 moderate
2 minor
|
|
|
68
|
| **`as={SecondaryButton}`**). Use **`React.forwardRef`** when the menu may open programmatically | ||
| before the user activates the target. | ||
|
|
||
| **Programmatic open without `Menu.Target`:** |
There was a problem hiding this comment.
I'm not sure I follow why we need this example. There's a bunch of things that fall off here if we don't use <Menu.Target> that normally supplies:
- an
idfor<Menu.List>to referencearia-labelledby aria-haspopuparia-expanded- Down arrow key events to open the menu
- The return focus target when menu is dismissed
I think we should remove this example. People can just use the as prop to customize the target to suit their needs. (E.g. as={PrimaryButton})
| <Menu.List> | ||
| <Menu.Item>First Item</Menu.Item> | ||
| <Menu.Item>Second Item</Menu.Item> | ||
| <Menu.Item aria-disabled>Unavailable Item</Menu.Item> |
There was a problem hiding this comment.
Let's take out aria-disabled from the minimum structure.
| - Use native **`disabled`** (or deprecated **`isDisabled`**) instead of **`aria-disabled`** when | ||
| the item should remain discoverable | ||
| - Skip **`data-text`** on static items whose accessible/filter text is not plain string children | ||
| - Use a custom **`Menu.Target`** **`as`** component **without** **`forwardRef`** when the menu can |
There was a problem hiding this comment.
Either remove or consider revising in some way.
| | When | Default behavior | Ask the developer before overriding | | ||
| | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | Menu **opens** | Focus moves to the **first menu item** by default via item focus hooks—not `useInitialFocus`. Omit **`initialFocusRef`**. | _Which item should receive focus when the menu opens?_ Prefer item order / `data-id` registration; do not assume **`initialFocusRef`** works on Menu. | | ||
| | Menu **closes** | **`useReturnFocus`** moves focus to **`Menu.Target`**. Omit **`returnFocusRef`**. | _Which element should receive focus when the menu closes?_ (When there is no **`Menu.Target`**, set **`returnFocusRef`** on **`useMenuModel({returnFocusRef})`**, or when return focus should land elsewhere.) | |
There was a problem hiding this comment.
Consider removing "When there is no Menu.Target ..."
| | Complex item content / icons _(conditional)_ | For static API when children are not plain text, set **`data-text`** on **`Menu.Item`** so typeahead/filtering can resolve the item text. Decorative icons alongside **`Menu.Item.Text`** usually need no extra accessible name. | | ||
| | Groups _(conditional)_ | **`Menu.Group`** with **`title`** or **`Menu.Group.Heading`** so `role="group"` is labeled. Group headers are not keyboard-selectable. | | ||
| | Nested menus _(conditional)_ | **`Menu.Submenu`** with **`Menu.Submenu.TargetItem`** plus **`Popper` / `Card` / `List` / `Item`**. Do not manually set submenu `aria-haspopup` / `aria-expanded`. | | ||
| | Multi-select menu _(conditional)_ | `mode="multiple"` on the model when items should toggle selection without closing. Ask before changing from default `single`. | |
There was a problem hiding this comment.
Hang on, we can select multiple options in a menu? How do we toggle a selection state on a menu? The menu item role doesn't support aria-selected ...
This feels like it also contradicts the instructions 2 lines below: Use Select or Combobox for selectable options.
Summary
Restructure Menu accessibility docs to match the Dialog/FormField pattern with minimum structure, built-in behaviors, requirements, and anti-patterns for codegen.
Release Category
Components
Checklist
ready for reviewhas been added to PRFor the Reviewer
Where Should the Reviewer Start?
/modules/react/menu/stories/Menu.mdx
Areas for Feedback? (optional)
Updated the accessibility section for the Menu component. PLease review the content for accuracy and clarity for AI code generation.
Testing Manually
Review the storybook page for Menu and ensure that the accessibility section renders correctly.