Skip to content

fix(button): render the ariaLabel prop as an aria-label attribute - #1796

Open
alexcpn wants to merge 1 commit into
dhis2:masterfrom
alexcpn:LIBS-734/button-aria-label
Open

alexcpn wants to merge 1 commit into
dhis2:masterfrom
alexcpn:LIBS-734/button-aria-label

Conversation

@alexcpn

@alexcpn alexcpn commented Nov 26, 2026 •

Copy link
Copy Markdown

Implements LIBS-734

Relates to LIBS-716 (make aria-label props consistent across UI components)


Description

Input and MenuItem take an ariaLabel prop, and the Button stories use ariaLabel too (button.prod.stories.js). But Button had no such prop: it spread ariaLabel onto the <button> as an unknown attribute. The DOM ended up with arialabel="...", which assistive technology ignores, so an icon-only button still had no accessible name. The "missing title and ariaLabel" debug message also fired, because it only checked aria-label.

The existing test has the accessibility attributes asserted this broken attribute (toHaveAttribute('ariaLabel', ...), which matches arialabel because HTML attribute names are case-insensitive).

This PR:

  • adds an ariaLabel prop to Button that renders aria-label
  • keeps the native aria-label prop working. It is spread after, so it takes precedence if both are passed (no change for current users)
  • counts ariaLabel in the missing-label debug check
  • adds ariaLabel to ButtonProps in the types (only Button, not BaseButtonProps, since SplitButton/DropdownButton don't forward it) and regenerates API.md

How it was tested

  • New tests: an icon-only button gets its accessible name from ariaLabel (getByRole('button', { name })); native aria-label still works; native aria-label wins when both are set; no debug warning when only ariaLabel is set. The existing accessibility test now asserts aria-label and the absence of arialabel.
  • On master, three of these fail (including the updated existing test). With the change, all 26 button tests pass.
  • eslint and prettier --check are clean (one existing react-hooks/exhaustive-deps warning in button.js is untouched).

Known issues


Checklist

  • API docs are generated
  • Tests were added
  • Storybook demos were added

The existing stories already pass ariaLabel; with this change it now takes effect.


AI disclosure

This change was written and tested by an AI model, Claude Opus 5.5 (via Claude Code), and submitted by a human contributor.

#T4G (tokens for good project)

🤖 Generated with Claude Code

@alexcpn
alexcpn requested a review from a team as a code owner November 26, 2026 14:12
Button passed unknown props straight to the <button>, so `ariaLabel`
(used in the Button stories, and the prop name used by Input and
MenuItem) ended up as a meaningless `arialabel` attribute and the button
had no accessible name. Add an ariaLabel prop that renders `aria-label`.
The native `aria-label` prop still works and takes precedence.

Implements LIBS-734

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexcpn
alexcpn force-pushed the LIBS-734/button-aria-label branch from 8a75289 to 4a409c4 Compare December 4, 2026 13:44
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant