Fix button-name in React
React apps frequently ship icon-only <button> wrappers around Lucide, Heroicons, or FontAwesome SVGs without visible text. Making aria-label a required TypeScript prop on a dedicated <IconButton> component catches missing names in the IDE before code ever reaches staging or production.
Before and after
// Broken React icon button: Lucide icon with zero accessible name
import { Search } from "lucide-react";
export function HeaderSearchTrigger({ onOpen }: { onOpen: () => void }) {
return (
<button type="button" className="icon-btn" onClick={onOpen}>
<Search size={18} />
</button>
);
}// Fixed React IconButton: TypeScript enforces a non-empty accessible label
import type { ButtonHTMLAttributes, ReactNode } from "react";
import { Search } from "lucide-react";
interface IconButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
label: string;
icon: ReactNode;
}
export function IconButton({ label, icon, type = "button", ...props }: IconButtonProps) {
return (
<button type={type} aria-label={label} {...props}>
<span aria-hidden="true">{icon}</span>
</button>
);
}
export function HeaderSearchTrigger({ onOpen }: { onOpen: () => void }) {
return <IconButton label="Open site search" icon={<Search size={18} />} onClick={onOpen} />;
}Fixed vs. broken example
Tab to each button and inspect the Accessibility pane in DevTools: the broken control exposes an empty Name while the fixed control exposes "Open site search".
Playwright + axe-core check
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
test("React icon buttons expose accessible names via getByRole", async ({ page }) => {
await page.goto("/dashboard");
await expect(page.getByRole("button", { name: "Open site search" })).toBeVisible();
const results = await new AxeBuilder({ page })
.withRules(["button-name"])
.analyze();
expect(results.violations).toEqual([]);
});Template deduplication tip
When an unlabeled <CloseModalButton /> or table action menu renders across dozens of dashboard views, A11yDrift consolidates every instance into one root React component cluster so a single typed IconButton refactor resolves them all.
What NVDA and VoiceOver announce
Blind screen-reader users and voice-dictation users (Dragon, Voice Control) encounter unlabeled icon buttons as generic 'button' controls with no clue whether activating them opens search, closes a modal, or deletes an item.
NVDA (Windows)
"button" (silence — no action name announced)
"Open site search, button"
VoiceOver (macOS / iOS)
"button" (unlabeled interactive element)
"Open site search, button"
Common questions
Why is a <button> better than <div onClick> with aria-label in React?
What if my React button has both an icon and visible text?
Should icon buttons include the word 'button' inside aria-label?
Test a URL for button-name
Enter any public URL for a free WCAG 2.2 AA check—no account or credit card required.
Shipping React weekly? Block new button-name regressions in PRs with our baseline-diff GitHub Action PR gate (≤20 URLs/PR).