patternfly / patternfly/react-data-view
DataViewFilters: MenuToggle for filter category selector has no accessible name
还没有人认领这个 Issue。
- 主要语言
- TypeScript
- 星标
- 4
- 派生
- 21
- PR 合并指标
- 30 天内没有已合并 PR
描述
Description
The DataViewFilters component renders a MenuToggle as the filter category selector (e.g., to switch between "Name" and "Label" filters). This button has no accessible name, causing a critical button-name axe violation (WCAG 4.1.2).
Root cause
activeAttributeMenuis initialized as''(line 46)- It's only populated via
useEffectafter the first render (lines 63–65) - The
MenuTogglehas noaria-labelprop (lines 80–88)
On the initial render, the button has no text content, no aria-label, no aria-labelledby, and no title — making it completely invisible to screen readers.
// Line 46 — empty initial state
const [activeAttributeMenu, setActiveAttributeMenu] = useState<string>('');
// Lines 80-88 — no aria-label, children is '' on first render
const attributeToggle = (
<MenuToggle
ref={attributeToggleRef}
onClick={() => setIsAttributeMenuOpen(!isAttributeMenuOpen)}
isExpanded={isAttributeMenuOpen}
icon={toggleIcon}
>
{activeAttributeMenu}
</MenuToggle>
);
Suggested fix
Two changes:
-
Initialize
activeAttributeMenufrom the first child'stitleprop synchronously instead of viauseEffect, so it's never empty:const initialTitle = useMemo(() => filterItems[0]?.title ?? '', []); const [activeAttributeMenu, setActiveAttributeMenu] = useState<string>(initialTitle); -
Add a fallback
aria-labelon theMenuToggle:<MenuToggle aria-label="Filter by" ... >
How to reproduce
Render DataViewFilters with 2+ filter children and run axe-core:
<DataViewFilters>
<DataViewTextFilter filterId="name" title="Name" />
<DataViewTextFilter filterId="label" title="Label" />
</DataViewFilters>
axe reports:
critical button-name: Buttons must have discernible text
Target: .pf-m-filter-group > div:nth-child(1) > .pf-v6-c-menu-toggle
Environment
-
@patternfly/react-data-view: 6.5.0 -
Detected by: axe-core 4.11 via
@axe-core/playwright
Related
- #21 (DataView accessibility meta-issue)
Jira Issue: PF-4416
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 packages/module/src/DataViewFilters/DataViewFilters.tsx 开始,检查第 46 行和第 80–88 行附近的 activeAttributeMenu 状态和 MenuToggle。使用 issue 中的 Name 和 Label filter children 渲染 DataViewFilters,然后运行 axe-core。完成的标准是:筛选器类别选择器在初始渲染时具有可辨识的 accessible name,并且关键的 button-name violation 已消失。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- react, typescript
- 领域
- accessibility, frontend
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 78/100