patternfly / patternfly/react-data-view

DataViewFilters: MenuToggle for filter category selector has no accessible name

Open Beginner friendly
#680 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4
Forks
21
PR merge metrics
No merged PRs in 30d

Description

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

In DataViewFilters.tsx:

  1. activeAttributeMenu is initialized as '' (line 46)
  2. It's only populated via useEffect after the first render (lines 63–65)
  3. The MenuToggle has no aria-label prop (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:

  1. Initialize activeAttributeMenu from the first child's title prop synchronously instead of via useEffect, so it's never empty:

    const initialTitle = useMemo(() => filterItems[0]?.title ?? '', []);
    const [activeAttributeMenu, setActiveAttributeMenu] = useState<string>(initialTitle);
    
  2. Add a fallback aria-label on the MenuToggle:

    <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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/module/src/DataViewFilters/DataViewFilters.tsx, reviewing the activeAttributeMenu state and the MenuToggle around lines 46 and 80–88. Render DataViewFilters with the Name and Label filter children from the issue, then run axe-core. Done means the filter category selector has a discernible accessible name on the initial render and the critical button-name violation is gone.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
accessibility, frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.