React fix

Before and after

Broken — before
// 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 — after
// 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} />;
}
Live preview

Fixed vs. broken example

Passes button-name
Accessibility tree: role="button", accessible name="Open site search" (decorative SVG hidden with aria-hidden="true")

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".

Automated test

Playwright + axe-core check

tests/a11y-button-name.spec.ts
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.

Screen readers

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)

Broken

"button" (silence — no action name announced)


Fixed

"Open site search, button"

VoiceOver (macOS / iOS)

Broken

"button" (unlabeled interactive element)


Fixed

"Open site search, button"

Common questions

Why is a <button> better than <div onClick> with aria-label in React?
Native <button type='button'> elements automatically provide Enter/Space activation, focusability, and the button role without custom keydown handlers or tabIndex wiring.
What if my React button has both an icon and visible text?
When visible text is present (e.g. 'Delete'), omit aria-label so the visible text serves as the accessible name, and add aria-hidden='true' to the icon so it is not read twice.
Should icon buttons include the word 'button' inside aria-label?
No. Screen readers automatically append the role ('button'). Writing aria-label='Close dialog button' causes NVDA and VoiceOver to awkwardly speak 'Close dialog button, button'.