Skip to content
All posts

Accessibility Is a Design System Problem

9 min read
  • accessibility
  • design-systems
  • testing
  • frontend

Most accessibility bugs get filed against product teams, but they actually come from about forty components. How we fixed them in the design system and the tests that keep them fixed.


Contents

We ran an accessibility audit across our platform and got back a few thousand violations over hundreds of routes. The obvious next step is to file a few thousand tickets against a few dozen teams.

I've seen that approach kill accessibility work before, so we tried something else first. We grouped the violations by which component rendered the broken node. Most of them came from about forty components in our design system. If IconButton is missing a label in two hundred places, that's one bug. And none of the two hundred people who used it is the right person to fix it.

components behind the large majority of violations
~40components behind the large majority of violations
existing Storybook stories now scanned automatically
~600existing Storybook stories now scanned automatically
testing layers, each running where people already work
4testing layers, each running where people already work

I'm on the design system team, so yes, this conclusion suits me. I still think it's right.

Push every fix down as far as it will go

Any accessibility bug can be fixed in one of three places. Some are much better than others.

Fix lives inFixes how manyCaught whenSurvives a new consumer
Product codeOne instanceNever, someone files itNo
The componentEvery consumer, on version bumpNever, but only onceYes
Types or tokensEvery consumer, foreverAt compile timeCannot be got wrong

Fixing it in product code means someone adds aria-label="Close" to their dialog's close button. It's the cheapest fix, and the next person to write a dialog makes the same mistake.

Fixing it in the component means Dialog owns its close button, and that button owns its label. Nobody can get it wrong, and every existing consumer inherits the fix.

The third row is the only one that scales, because a review comment becomes a build error. Here's what that looks like. Our IconButton used to accept an icon and nothing else, so leaving out the label was the easy path:

components/icon-button.tsx
type Base = {
  icon: ReactNode;
  onClick?: () => void;
};
 
// Either you render visible text, or you supply an accessible name.
// There is no third option.
type IconButtonProps = Base &
  (
    | { children: ReactNode; "aria-label"?: string }
    | { children?: never; "aria-label": string }
  );

An icon-only button with no accessible name is now a type error. The editor flags it before review, while the person writing it still knows what the button does and can write a good label. That got rid of a whole category of violation for about twenty lines of code.

Same idea for tokens. Every component used to decide its own focus style, so every component could get it wrong. Now there's one --focus-ring token and one shared :focus-visible rule, and the build checks its contrast against every surface token. Focus rings don't come up in code review anymore.

Note

Do this for the components with real interaction behaviour: dialogs, menus, comboboxes, tabs, tooltips, toasts, data grids. Teams should never build these themselves, and they will if yours are hard to use.

Build it in, don't document it

We used to have a docs page on how to wire up a menu properly: roving tabindex, aria-activedescendant, arrow keys, escape to close, focus going back to the trigger. It was accurate and well written. Almost nobody followed it, because it asked every team to implement a spec correctly while on a deadline.

So the menu now does all of that itself, and you can't configure it away. You can't turn off focus return. There's no disableFocusTrap escape hatch on Dialog, because the one time we shipped an escape hatch, it showed up in eleven places within a quarter and every single one of them was a bug.

You also have to be clear about what a component can't know. Dialog can't pick its own accessible name, so it makes you pass one. It can manage its own focus, so it just does.

The testing workflow

Types and composition stop the mistakes we can rule out. Everything else has to be caught by a tool, as early as possible. We ended up with four layers, each cheap enough to run where it lives.

LayerToolRunsCatchesBlind to
Linteslint-plugin-jsx-a11yOn keystrokeMissing alt, invalid ARIA, positive tabindexAnything needing a render
Unitaxe on rendered outputOn commitPer-component violations in every stateHow components compose
StoryStorybook test runnerOn every story, freeReal markup, real styles, per variantFull-page structure
E2E@axe-core/playwrightOn key user flowsDuplicate landmarks, skipped headings, lost focusMeaning, and anything requiring judgement

Lint, in the editor. eslint-plugin-jsx-a11y, with the rules we care about set to errors. Nobody reads warnings. This catches the simple stuff: missing alt, click handlers on non-interactive elements, wrong ARIA attribute names, positive tabindex.

Unit tests, per component. Every design system component runs axe on its rendered output in every state that matters, including the ones people forget: disabled, loading, error, empty and open.

components/__tests__/menu.a11y.test.tsx
it.each(["closed", "open", "disabled"] as const)(
  "has no violations when %s",
  async (state) => {
    const { container } = render(<Menu {...propsFor(state)} />);
    expect(await axe(container)).toHaveNoViolations();
  }
);

Story scans, for free. This layer gave us the most for the least effort, because nobody had to write new tests. The Storybook test runner turns every story we already had into an accessibility test:

.storybook/test-runner.ts
import { injectAxe, checkA11y } from "axe-playwright";
 
export default {
  async preVisit(page) {
    await injectAxe(page);
  },
  async postVisit(page) {
    await checkA11y(page, "#storybook-root", {
      detailedReport: true,
      axeOptions: { runOnly: ["wcag2a", "wcag2aa"] },
    });
  },
};

That's about 600 stories, so about 600 accessibility checks, and nobody wrote a new test. Every story a team adds for its own reasons adds coverage too.

End-to-end, on real flows. @axe-core/playwright runs on a short list of key user flows: sign-in, the main workspace, publishing, and a couple of others. It's the only layer that sees components after product code has wrapped them in its own markup. So it catches what component tests can't: duplicate landmarks, skipped heading levels, focus that disappears after a route change.

And then there's what no tool covers. Once a quarter, and for every new interaction pattern, someone tests with only a keyboard and then with a screen reader. The usual claim is that automated tools catch a third to half of WCAG issues. That's roughly what we see.

  • Automated tooling can decide 40%
  • Needs a human 60%
The usual split, and roughly what we see. Everything right of the accent band needs a person. Four automated layers don't move the line. They just make the left side cheap.

Tools are great at "this input has no label." They can't tell you the label is there but says nothing useful. CI won't catch alt text that just says image, headings that are valid but make no sense in that order, or a focus order that works but jumps around the page.

Rolling it out without breaking every build

We didn't make CI fail on accessibility violations on day one. Every build in the company would have gone red at once and someone would have reverted the rule by lunch. I've watched a team do exactly that with type checking.

What we did instead: we saved every existing violation into a baseline file in the repo, keyed by rule and component. CI only fails on violations that aren't in the baseline. New code has to meet the real standard straight away, and old code becomes a list with a number on it.

Then we made the baseline only shrink. A check fails if anyone adds an entry. Teams cleared their parts at their own pace, and since the file lived in the repo and not in some dashboard nobody opened, you could see progress in pull requests.

Tip

Key the baseline by rule and component, never by file path and line number. Line-based baselines break on every unrelated refactor, so teams start regenerating the whole file, and then the baseline stops meaning anything.

What we measure

"Percentage of components with accessibility tests" is easy to push up and tells you almost nothing. We got it into the high nineties early on while the product was still full of violations. Component coverage says nothing about how components get put together.

Now we watch violations per thousand DOM nodes on real rendered pages, per route and per severity. It goes up when a team ships something careless, which is what we want to know. It looks worse on a slide, but it's far more useful for running a team.

We also track how many violations the design system causes. When that share drops, the components are doing their job and what's left is real product work.

What I'd tell someone starting this

Group your audit results by component before you write a single ticket. That grouping tells you whether this work can ever finish.

Spend the first month on types and composition, not tests. A bug nobody can write beats a bug you reliably catch.

And run the checks where people already work. The Storybook layer worked because it cost nobody anything. Every layer that asked teams to write new accessibility tests faded out within two quarters, however much everyone agreed it mattered.

ShareXLinkedIn

Thanks for reading. If it helped, tell me on X.