ActionMenu.Anchor should only accept button
メンテナーはふだん 1 日以内に返信
評価
この issue はまだ評価されていません。
説明
Description
ActionMenu has preferred API of ActionMenu.Button which uses a Primer Button 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
<ActionMenu.Anchor>
<div className="relative">
<IconButton aria-label="Filter files in tree" icon={FilterIcon} />
{filterEnabled && (
<div aria-label="Showing only files changed" className="active-indicator" />
)}
</div>
</ActionMenu.Anchor>
The above JSX renders inaccessible html:
<div
class="relative"
id=":rku:" <!-- used to label the menu when open, this should have been on the button? -->
aria-haspopup="true"
aria-expanded="false"
tabindex="0" <!-- tabindex=0 added by ActionMenu to make sure anchor gets focus -->
>
<button
data-component="IconButton"
type="button"
aria-labelledby=":rl0:" <!-- points to tooltip -->
aria-describedby=":rl1:-loading-announcement"
>
<svg aria-hidden="true"></svg>
</button>
<span
class="Tooltip__StyledTooltip-sc-e45c7z-0 iBBTma"
id=":rl0:"
aria-hidden="true"
popover="auto"
>
Filter files in tree
</span>
<div aria-label="Showing only changed files" class="absolute active-indicator"/>
</div>
https://github.com/user-attachments/assets/988470d7-0f1a-43a8-aa7b-3a874dc3cb33
Video description:
- Pressing tab on the close button seems to focus the filter button but does not show tooltip.
- The screen reader reads out "Filter files in tree, Showing only changed files, menu pop-up, group"
- You'd expect tabbing again would focus the text input, but it focuses the button instead. Now a tooltip is visible with text "Filter files in tree".
- The screen reader now reads "Filter files in tree, button, Filter files in tree, Showing only changed files, menu pop-up, group" (still reading out the group)
- Tabbing again finally focuses the text input
Proposed Solution
I have 2 suggestions:
- Reduce: The most common use case of
ActionMenu.Anchoris to use anIconButton, we should create a shortcutActionMenu.IconButtonas a companion toActionMenu.Button.
A blessed shortcut would reduce the chances of implementing it incorrectly. - Validate:
ActionMenu.Anchorshould 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 have
Steps to reproduce
Navigate to custom anchor story and replace the Anchor with:
<ActionMenu.Anchor>
<div className="relative">
<IconButton aria-label="Filter files in tree" icon={FilterIcon} />
{filterEnabled && (
<div aria-label="Showing only files changed" className="active-indicator" />
)}
</div>
</ActionMenu.Anchor>
Version
v37.5.0
Browser
Chrome
- 主要言語
- TypeScript
- スター
- 3.9k
- フォーク
- 691
- 平均マージ
- 3日 6時間
- マージ済み PR(30日)
- 54
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
primer/react のほかの issue
-
ActionMenu: add preventFocusOnClose対応中かも @tay1orjones が 4 日前に担当しました。 オープンcomponent: ActionMenu
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
primer/react#8488 · コメント 1 件 · リアクション 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
FormControl renders duplicate non-choice inputs when layout="horizontal"対応中かも @namangoyal176-10 が 4 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
PageHeader.Title does not seem to accept id prop対応中かも @minwookshin が 10 日前に担当しました。 オープンcomponent: PageHeader react staff
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
primer/react#8474 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
The padding prop seems to have no effect with PageLayout.Sidebar対応中かも @minwookshin が 10 日前に担当しました。 オープンcomponent: PageLayout react staff
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
primer/react#8470 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug component: Spinner react
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
primer/react#8423 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
NousResearch/hermes-agent#136483 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信
-
factory-active factory-automatic task-bug-reproduction-success task-identify-harness-labels-done task-identify-issue-type-done
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
[Bug]: Web chat input doesn't regain focus after a reply finishes対応中かも @GaijinSystems が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
zeroclaw-labs/zeroclaw#11658 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
babylonlabs-io/babylon-toolkit#2711 ·
メンテナーはふだん 1 日以内に返信