AI-Powered Full Stack Tutorial 0/70 lessons ~6 min read Lesson 8

    Accessible UI Engineering and Design Systems

    TechLearningPro signed an enterprise pilot that required WCAG 2.2 Level AA.

    Course progress0%
    Focus
    18 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    AI-Powered Full Stack Development · Lesson 08 · Full-Stack Engineering Foundations

    Lesson Overview

    TechLearningPro signed an enterprise pilot that required WCAG 2.2 Level AA. The lesson player from lesson 7 rendered the right outline, and a keyboard user still could not complete it. "Mark complete" was a div with an onClick. Focus disappeared when the note saved. Errors were red text with no link to the field. A model experiment had emitted a second player made of styled divs, and someone almost shipped it because the screenshot matched. The contract does not grade screenshots. It grades whether a learner can perceive, operate, and understand the UI, including with a keyboard and a screen reader.

    This lesson turns the player controls into a small design system: semantic elements, named fields, visible focus, status messages that assistive tech can hear, tokens for color and spacing, and tests that query by role. The React course and the Next.js course show how components mount. Here the question is whether those components are a product or a picture. Backend Engineering with Node.js is next; it will not fix a button that is not a button.

    Assumptions:

    • React 18 client components inside the lesson 7 island. Server Components may render the same semantic tags; they do not add accessibility by being on the server.
    • Target: WCAG 2.2 Level AA for the player controls you touch. This lesson is not a full-site audit and not legal advice. The W3C documents are the source of the criteria; re-read them when a criterion number matters in a contract.
    • Native HTML first. ARIA when no native element expresses the widget. The HTML <dialog> element and showModal() are used for a confirmation, not a hand-rolled focus trap.
    • Design tokens are CSS custom properties. No CSS-in-JS runtime is required.
    • Automated checks use Testing Library role queries and jest-axe (axe from jest-axe, plus toHaveNoViolations). Automation will not catch a confusing label. You still tab through the flow.
    • Model-generated markup is untrusted design input. It is rewritten onto these components. It is not injected with dangerouslySetInnerHTML.

    Learning Objectives

    By the end of this lesson you will be able to:

    1. Explain the four WCAG principles — perceivable, operable, understandable, robust — in terms of the lesson player.
    2. Choose a native element before adding ARIA, and name the first rule of ARIA.
    3. Associate labels, hints, and errors with a field using useId, htmlFor, aria-describedby, and aria-invalid.
    4. Build buttons, checkboxes, and a dialog that work with a keyboard and expose an accessible name.
    5. Keep visible focus and respect prefers-reduced-motion.
    6. Announce async save results with role="status" or a polite live region without moving focus by surprise.
    7. Encode color and spacing as tokens, and pair color with text so status is not color alone.
    8. Treat a design-system component as an API: variants as a union, required accessible names, no div click targets.
    9. Reject model-authored HTML as a rendering strategy.
    10. Test with getByRole and axe, and list what those tests do not prove.
    11. Write a short accessibility note a reviewer can check: names, keyboard path, contrast token, error link.
    12. Leave the server authorization rules of lesson 7 unchanged. Hiding a control is not access control.

    Prerequisites

    • Lesson 5's LessonOutline and lesson 7's LessonIsland. You will replace clickable non-controls and unlabeled areas, not the data flow.
    • TypeScript for Production Full-Stack Development so variants and props are unions, not strings you hope are valid.
    • Ability to use browser DevTools to tab through a page and to read the accessibility tree at a basic level. You do not need to be a screen-reader specialist to finish the assignment. You do need to try the keyboard path.
    • Optional: the React course section on forms if controlled inputs are still uncomfortable.

    If the player "works with a mouse on your laptop," assume it is not done.

    Detailed Core Concepts

    What accessible UI engineering is for

    Accessibility means people can use the player with the senses and input methods they have: sight, hearing, keyboard, voice, screen readers, zoom, reduced motion. WCAG organizes this as four principles:

    • Perceivable. Information is not only color, not only a placeholder, not a background image of text.
    • Operable. Keyboard users can reach and run every control. Focus is visible. Time limits and motion do not trap people.
    • Understandable. Labels and errors say what to do. The save result is text, not a color shift.
    • Robust. The accessibility tree exposes name, role, and value so assistive tech and tests can read them.

    A design system is how you stop re-deciding those rules in every feature. Tokens hold the visual values. Components hold the semantics. Feature code composes them and passes real names ("Save note"), not a generic "Submit" reused for three different actions on one page.

    Why it exists on an AI product

    Model output and generated UI increase the rate of unmarked controls. A model will happily return a div that looks like a button, a placeholder instead of a label, and a contrast pair that fails AA. If you render that HTML, you ship the failure at the speed of generation. The engineering response is a closed set of components and a rule: generated suggestions become props to those components, or they do not ship.

    Accessibility is also a reliability feature. The same missing name that blocks a screen reader blocks your Testing Library query. Teams that query by class miss both bugs.

    Native elements and the first rule of ARIA

    The first rule of ARIA: if a native HTML element has the semantics you need, use it. Do not recreate a button.

    NeedUseAvoid
    Action<button type="button">div with onClick
    Navigation<a href> or Next.js Linkbutton that assigns location to an internal route when a link is honest
    Checkbox<input type="checkbox"> inside a <label>aria-checked on a div
    Text<input> or <textarea> with a <label>placeholder as the only name
    Dialog<dialog> with showModal()a div with role="dialog" unless you implement focus behavior you have tested
    Status<p role="status">color change only

    ARIA roles are for widgets HTML does not have, or for repairing a composite you truly must build. When you use a role, you take on its keyboard pattern. The ARIA Authoring Practices Guide describes those patterns. Copying role="button" without Enter and Space handlers fails both the guide and the contract.

    div and span are not focusable and have no button role. Adding tabIndex={0} plus a click handler is the long way back to <button>, usually missing disabled behavior and form semantics.

    Name, role, and value

    Assistive technologies need:

    • Role — button, checkbox, dialog, heading.
    • Name — the accessible name from the label text, aria-label, or aria-labelledby. Prefer visible text. aria-label is for a control whose visible design is an icon, and the name must still exist.
    • Value / state — checked, expanded, invalid, disabled.

    useId from React 18 generates a stable id for htmlFor and aria-describedby when you have more than one field. Do not hard-code id="note" if two islands can mount.

    Accessible name calculation has an order defined by the spec. Practical rule: visible label text associated with htmlFor is the right default. Do not set aria-label to a different phrase than the visible label; speech and sight then disagree.

    Focus

    Focus order follows the DOM order of focusable controls, unless you deliberately move it. Do not tabIndex={5} your way into a custom order. Fix the DOM order.

    :focus-visible styles must be obvious against the tokenized background. Removing outline in CSS without a replacement fails operable WCAG criteria for focus visibility. A token --focus-ring keeps the ring consistent.

    When a confirm dialog opens with showModal(), the browser focuses the dialog and makes the rest of the page inert. Call close() to return focus to the invoker in supporting browsers; also return focus yourself to the button that opened it if you need a guarantee. Do not build a manual focus trap in this lesson.

    Do not move focus to a status message on every save. A polite live region announces it. Move focus when the context truly changes, such as opening a dialog.

    Forms and errors

    Each field has a visible label. Placeholder text disappears and is not a label. Hint text and error text have ids. The field sets aria-describedby to those ids and aria-invalid={true} when the error is showing. The error is text near the field, not only a toast. Color is not the only signal: include the word "Error" or an equivalent text prefix.

    Disabled submit buttons need a reason the user can discover. Prefer leaving the button enabled and showing the validation error, or explain the disabled state in text. disabled removes the control from the tab order, so a keyboard user cannot focus it to learn why.

    Color, contrast, and tokens

    WCAG 2.2 AA contrast, as published by W3C: normal text at least 4.5:1, large text at least 3:1, and user-interface component boundaries and focus indicators at least 3:1 against adjacent colors. Do not invent a different ratio in the design system. If a token pair fails, change the token, not the criterion.

    Tokens live in CSS variables:

    css
    :root {
    --color-text: #1b1b1f;
    --color-surface: #ffffff;
    --color-danger: #9b1c1c;
    --color-focus: #0b57d0;
    --space-2: 0.5rem;
    --focus-ring: 0 0 0 3px var(--color-focus);
    }

    These values are a starting point you must check with a contrast tool. Do not assume a hex pair passes because it looks fine on a calibrated monitor. Non-text status uses an icon or a word in addition to --color-danger.

    prefers-reduced-motion: reduce turns off non-essential transitions. A spinning decoration is not required to understand "Saving…". The text is.

    Dialogs and confirmation

    Marking a lesson complete can be immediate, as in lesson 7, or confirmed. If you confirm, use <dialog>. showModal() is the method that presents it as a modal. The dialog needs a heading and a close control that is a button. Escape closes a modal dialog in supporting browsers. Initial focus and background inertness are why this lesson prefers the native element over a div.

    Design system shape

    text
    src/design-system/
    tokens.css
    Button.tsx
    TextField.tsx
    StatusMessage.tsx
    ConfirmDialog.tsx
    Button.test.tsx
    TextField.test.tsx

    Component rules:

    • Button renders <button type="button"> unless type="submit".
    • Variants are "primary" | "ghost" | "danger", mapped to classes, not a free className that can remove the focus ring. You may allow an extra className only if it cannot unset the ring. Safer: no className prop in v1.
    • TextField requires label: string. There is no unlabeled mode.
    • Icon-only buttons require name: string and set aria-label.
    • Components do not fetch, do not read the session, and do not decide authorization.

    AI-generated UI

    If a model proposes markup, treat it as a sketch. Map it onto Button, TextField, and headings. Refuse to mount a string of HTML. Prompt-injection text inside a lesson note is still text in TextField's value; it is not instructions to your design system. Later security lessons cover prompts. This lesson covers the rendering edge: text nodes and known components only.

    Do not ask a model to be the accessibility approver. Use it, if you do, to draft a checklist you then verify with keyboard, axe, and the W3C criterion. The model does not sign the contract.

    Architecture and Design Diagrams

    flowchart TB
      subgraph page [Lesson route]
        Page[Server page from lesson 7]
        Island[LessonIsland client]
      end
    
      subgraph ds [Design system]
        Tokens[CSS tokens]
        Button[Button]
        Field[TextField]
        Status[StatusMessage]
        Dialog[dialog element]
      end
    
      subgraph at [Accessibility tree]
        Name[Accessible name]
        Role[Role]
        State[State]
      end
    
      Page --> Island
      Island --> Button
      Island --> Field
      Island --> Status
      Island --> Dialog
      Tokens --> Button
      Tokens --> Field
      Button --> Role
      Field --> Name
      Status --> State
    text
    keyboard user
    -> Tab lands on button or field in DOM order
    -> visible focus ring from --focus-ring
    -> Enter or Space activates the button
    -> action from lesson 7 runs
    -> StatusMessage with role=status announces fixed copy
    -> focus stays put unless a dialog opened
    screen reader
    -> heading level of the lesson title
    -> checkbox name from the label
    -> field name from htmlFor
    -> invalid state plus described error text

    Trust boundary: an accessible control can still call an unauthorized action. Lesson 7's deny-by-default stays. Accessibility does not make the client trustworthy. Conversely, a secure API behind an unlabeled control is a product the contracted learner cannot use.

    Technical Explanation

    When the note field renders:

    1. useId produces an id prefix for this mount.
    2. The <label htmlFor={inputId}> points at the textarea.
    3. The hint and the optional error each have ids.
    4. aria-describedby lists the hint and, when present, the error.
    5. aria-invalid is true only when the error is present.
    6. The accessibility tree exposes a textbox whose name is the label text and whose description includes the hint.

    When the learner activates a Button:

    1. The element is a real button, so Enter and Space activate it without extra key handlers.
    2. type="button" prevents an accidental form submit.
    3. disabled or aria-disabled is a conscious choice. This system uses disabled while isPending is true and shows "Saving…" in a status message so the state is not only a dim button.
    4. The click handler is the lesson 7 toggle or save. The design system does not know about lessons.

    When the dialog opens:

    1. The component calls dialogRef.current?.showModal().
    2. The browser treats it as modal.
    3. Confirm runs the action. Cancel or Escape calls close().
    4. Focus returns to the opener stored in a ref.

    prefers-reduced-motion is a media query in CSS. It does not require JavaScript. Components must not set inline transitions that ignore it.

    Practical Implementation

    Import tokens.css from the root layout in lesson 7 so Server-rendered pages and the island share variables.

    Simple example: tokens and a button

    css
    /* src/design-system/tokens.css */
    :root {
    --color-text: #1b1b1f;
    --color-surface: #ffffff;
    --color-danger: #9b1c1c;
    --color-focus: #0b57d0;
    --space-2: 0.5rem;
    --focus-ring: 0 0 0 3px var(--color-focus);
    }
    :focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    }
    @media (prefers-reduced-motion: reduce) {
    * {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
    }
    }

    The universal reduced-motion rule is a blunt instrument that is acceptable for this player. If a later view needs a meaningful animation, scope the override instead of deleting the query.

    tsx
    // src/design-system/Button.tsx
    import { forwardRef, type ButtonHTMLAttributes } from "react";
    type ButtonProps = {
    variant?: "primary" | "ghost" | "danger";
    name?: string;
    } & Omit<ButtonHTMLAttributes<HTMLButtonElement>, "className">;
    export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(
    { variant = "primary", name, type = "button", children, ...rest },
    ref,
    ) {
    const iconOnly = name !== undefined && (children === undefined || children === null);
    return (
    <button ref={ref} type={type} data-variant={variant} aria-label={iconOnly ? name : undefined} {...rest}>
    {children ?? name}
    </button>
    );
    });

    React 18 does not pass ref as a normal prop. forwardRef is what lets ConfirmDialog return focus to the opener. React 19 allows ref without forwardRef; stay on the React 18 form in this course.

    If both children and name are passed, the visible children provide the accessible name and name is not forced into aria-label. Icon-only use passes name and no children. There is no className prop, so a feature cannot strip the focus ring with a utility class. Variant styling uses [data-variant="danger"] in CSS next to the tokens. Check the danger text color against --color-surface with a contrast checker before you call the token done.

    Intermediate example: text field with error wiring

    tsx
    // src/design-system/TextField.tsx
    import { useId, type TextareaHTMLAttributes } from "react";
    type TextFieldProps = {
    label: string;
    hint?: string;
    error?: string;
    } & Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, "id" | "aria-describedby" | "className">;
    export function TextField({ label, hint, error, ...rest }: TextFieldProps) {
    const reactId = useId();
    const inputId = `${reactId}-input`;
    const hintId = `${reactId}-hint`;
    const errorId = `${reactId}-error`;
    const describedBy = [hint ? hintId : null, error ? errorId : null].filter(Boolean).join(" ") || undefined;
    return (
    <div>
    <label htmlFor={inputId}>{label}</label>
    <textarea
    id={inputId}
    aria-invalid={error ? true : undefined}
    aria-describedby={describedBy}
    {...rest}
    />
    {hint ? <p id={hintId}>{hint}</p> : null}
    {error ? (
    <p id={errorId} role="alert">
    Error: {error}
    </p>
    ) : null}
    </div>
    );
    }

    role="alert" on the error is assertive enough for a correction the learner must fix now. Do not also pop a second toast that repeats a stack trace. The error string is your copy, not a raw exception.

    tsx
    // src/design-system/StatusMessage.tsx
    export function StatusMessage({ children }: { children: string }) {
    return <p role="status">{children}</p>;
    }

    role="status" implies a polite live region. Update the text when the save finishes. Do not include the learner's note in the status string.

    Enterprise example: dialog and the player composition

    tsx
    // src/design-system/ConfirmDialog.tsx
    import { useId, useRef } from "react";
    import { Button } from "./Button";
    type ConfirmDialogProps = {
    title: string;
    confirmLabel: string;
    onConfirm: () => void;
    };
    export function ConfirmDialog({ title, confirmLabel, onConfirm }: ConfirmDialogProps) {
    const dialogRef = useRef<HTMLDialogElement>(null);
    const openerRef = useRef<HTMLButtonElement>(null);
    const titleId = useId();
    return (
    <>
    <Button ref={openerRef} variant="primary" onClick={() => dialogRef.current?.showModal()}>
    {confirmLabel}
    </Button>
    <dialog ref={dialogRef} aria-labelledby={titleId}>
    <h2 id={titleId}>{title}</h2>
    <Button
    variant="ghost"
    onClick={() => {
    dialogRef.current?.close();
    openerRef.current?.focus();
    }}
    >
    Cancel
    </Button>
    <Button
    variant="danger"
    onClick={() => {
    dialogRef.current?.close();
    onConfirm();
    openerRef.current?.focus();
    }}
    >
    Confirm
    </Button>
    </dialog>
    </>
    );
    }

    Button already forwards ref. useId keeps aria-labelledby unique when two dialogs mount. Do not hard-code id="confirm-title".

    Compose the island:

    tsx
    // inside LessonIsland, client component
    import { StatusMessage } from "../../design-system/StatusMessage";
    import { TextField } from "../../design-system/TextField";
    // note and message are existing React state from the player
    <TextField
    label="Lesson note"
    hint="Visible only to you on this account."
    error={note.length > 500 ? "Use 500 characters or fewer." : undefined}
    value={note}
    maxLength={500}
    onChange={(event) => setNote(event.target.value)}
    />
    {message ? <StatusMessage>{message}</StatusMessage> : null}

    The outline checkboxes from lesson 5 already use labels. Keep that. Add a page heading hierarchy: one h1 for the lesson title in the island, and do not skip to h3 for the outline if nothing is an h2. The confirm dialog's h2 is inside the dialog, which is acceptable if the dialog is labeled. Do not ship two h1 elements that repeat different product names.

    Skip link, in the root layout body, as the first focusable element:

    tsx
    <a href="#main">Skip to lesson</a>
    // ...
    <main id="main">{children}</main>

    Style the skip link so it is visible on focus. A skip link that is display: none does not exist for keyboard users. Use a visually hidden-until-focus pattern, and check it by tabbing from a fresh load.

    Security

    Accessible names must not include secrets, raw tokens, or other learners' data. A button named with a session id would read that id aloud and into logs from test output.

    aria-describedby text is still content. Pass your own error strings. Do not pass error.message from a failed fetch if that message echoes the note or an upstream URL. Lesson 7's fixed copy ("That update was not accepted.") belongs in StatusMessage.

    Do not render model HTML inside a design-system escape hatch. A prop such as html on TextField should not exist. Attackers and models both produce strings; the component API refuses to interpret them as markup.

    Hiding a dangerous action with CSS, or showing it only to a client-side "admin" role, is not authorization. The control can be absent for clarity, and the server must still deny the call. An accessible admin button that anyone can trigger is a worse bug, not a better one.

    Focus management must not be the only security boundary. Returning focus is a usability requirement. The action's allow-list of ids remains the security requirement.

    Dialog content is in the page DOM even when closed, depending on browser behavior for <dialog>. Do not put secrets in the dialog body "because it is closed."

    Testing

    Role queries are the default:

    tsx
    import { render, screen } from "@testing-library/react";
    import userEvent from "@testing-library/user-event";
    import { describe, expect, it, vi } from "vitest";
    import { Button } from "./Button";
    import { TextField } from "./TextField";
    describe("Button", () => {
    it("exposes the visible label as its name", async () => {
    const user = userEvent.setup();
    const onClick = vi.fn();
    render(<Button onClick={onClick}>Save note</Button>);
    await user.click(screen.getByRole("button", { name: "Save note" }));
    expect(onClick).toHaveBeenCalledOnce();
    });
    it("names an icon-only button from the name prop", () => {
    render(<Button name="Close dialog" />);
    expect(screen.getByRole("button", { name: "Close dialog" })).toBeTruthy();
    });
    });
    describe("TextField", () => {
    it("associates the error with the field", () => {
    render(<TextField label="Lesson note" error="Use 500 characters or fewer." />);
    const field = screen.getByRole("textbox", { name: "Lesson note" });
    expect(field.getAttribute("aria-invalid")).toBe("true");
    expect(screen.getByRole("alert")).toHaveTextContent("Use 500 characters or fewer.");
    });
    });

    toHaveTextContent and toHaveBeenCalledOnce need the matchers you configured (@testing-library/jest-dom and Vitest). If those matchers are not installed, assert with textContent and toHaveBeenCalledTimes(1) so the test still runs.

    Axe:

    tsx
    import { axe } from "jest-axe";
    import { render } from "@testing-library/react";
    import { TextField } from "./TextField";
    it("has no axe violations in the labeled state", async () => {
    const { container } = render(
    <main>
    <TextField label="Lesson note" hint="Plain text only." />
    </main>,
    );
    expect(await axe(container)).toHaveNoViolations();
    });

    You must register the matcher once in the test setup, as jest-axe documents: expect.extend(toHaveNoViolations). A failing axe run is a failed test, not a warning you baseline on day one for new components.

    What automation misses: a label that is technically present and factually wrong ("Name" on a note field), a focus order that is legal and confusing, contrast you never ran because the token is an image, and a dialog you never opened with the keyboard. The assignment requires one manual keyboard pass: tab from the skip link to the note, trigger save, hear or see the status text, open and cancel the dialog with Escape.

    eslint-plugin-jsx-a11y rules worth enabling on the design-system folder: alt-text, anchor-is-valid, label-has-associated-control, click-events-have-key-events, no-static-element-interactions, no-noninteractive-element-interactions. The plugin is a backstop. The component API is the real control, because feature code should not be able to render a div button through Button.

    Performance

    Accessibility work here is mostly DOM quality, not a runtime tax.

    • One design-system CSS file avoids per-component style recalculation from a CSS-in-JS runtime. If you later add a runtime, measure it. Do not add one for tokens.
    • useId is cheap and prevents duplicate-id bugs that cause assistive tech to read the wrong field. Duplicate ids are both a bug and a support cost.
    • Do not put aria-live="assertive" on a region that updates every keystroke. Polite status on commit is enough. Assertive alerts are for the error that just appeared.
    • Reduced motion removes animations that would otherwise keep the main thread busy on low-end devices. It is also the correct accessibility behavior.
    • Virtualizing the outline is a later performance project. If you virtualize, you must preserve keyboard access to off-screen items. Do not virtualize in this lesson and strand focus.
    • Icons as inline SVG need aria-hidden="true" when the button already has a text name, so the name is not announced twice. That is semantics, and it avoids noisy trees on large lists.

    Enterprise Real-World Scenarios

    Scenario A: Div button in the pilot

    The control looked right and did not appear in the tab order. The enterprise reviewer failed the flow in one pass.

    What good looks like. Button renders a button. A test queries it by role and name. jsx-a11y forbids the div pattern in feature code.

    Scenario B: Placeholder as label

    "Add a note" was placeholder text. On focus it vanished. Voice users and magnifier users lost the purpose of the field.

    What good looks like. TextField requires label. Placeholder is unused in this component's public API.

    Scenario C: Red border only

    The note over 500 characters got a red border. The status color was the only signal. A color-blind reviewer and axe's color-contrast check were only half of it; the missing text failed even when contrast passed.

    What good looks like. Error: text in an alert associated with the field, plus a token pair you have checked.

    Scenario D: Generated HTML player

    A prototype rendered a model's <div class="btn"> string into the island. It matched the mock and failed the keyboard test. It was also an XSS path if the model echoed markup.

    What good looks like. The model may suggest a label string. The island passes that string as children of Button after a human checks it, or drops it. No HTML sink.

    Scenario E: Focus lost on save

    The island re-mounted the outline by changing a key on the parent after every save. Focus returned to the body. Keyboard users restarted from the skip link.

    What good looks like. Update status text without remounting the form. Restore focus only when you intentionally open or close a dialog. Test that the note field remains the active element after a failed validation.

    Best Practices

    1. Use native elements before ARIA.
    2. Give every control a visible name, and make the accessible name match it.
    3. Require label on text fields in the type definition.
    4. Associate hints and errors with aria-describedby.
    5. Set aria-invalid when an error is visible.
    6. Use type="button" unless the button submits a form.
    7. Style :focus-visible with a token. Do not remove outlines without a replacement.
    8. Keep DOM order equal to reading and tab order.
    9. Use <dialog>.showModal() instead of a custom trap for this player.
    10. Return focus to the opener when the dialog closes.
    11. Announce save results with role="status" and fixed copy.
    12. Do not use color as the only status signal.
    13. Check token contrast against WCAG 2.2 AA ratios from the W3C spec, with a real checker.
    14. Honor prefers-reduced-motion.
    15. Put one h1 on the lesson page and do not skip heading levels.
    16. Include a skip link that becomes visible on focus.
    17. Query tests by role and name.
    18. Run axe on new design-system components and fix violations rather than baselining them.
    19. Forbid HTML injection props on design-system components.
    20. Keep authorization on the server. Accessibility changes the control, not the trust boundary.
    21. Use useId whenever a label relationship needs an id.
    22. Forward refs on Button with forwardRef on React 18.
    23. Hide decorative icons from the accessibility tree with aria-hidden.
    24. Prefer enabling a control and showing an error over a disabled control with no explanation.
    25. Review model-generated UI as a sketch that must be rewritten onto the design system.

    Common Mistakes and Anti-Patterns

    1. div with onClick. Symptom: not in the tab order, no button role. Cause: styling convenience. Fix: Button.
    2. Placeholder as the only label. Symptom: name disappears on input. Cause: mock-driven UI. Fix: required label prop.
    3. aria-label that contradicts visible text. Symptom: screen reader and sighted reviewer disagree. Cause: two names. Fix: one visible label.
    4. Outline removed globally. Symptom: keyboard users cannot see focus. Cause: a CSS reset. Fix: :focus-visible with --focus-ring.
    5. Positive tabIndex. Symptom: chaotic order. Cause: trying to match a mock. Fix: reorder the DOM.
    6. Error only in a toast. Symptom: the field does not expose aria-invalid. Cause: notification component reused for validation. Fix: inline alert wired with aria-describedby.
    7. Color-only complete state. Symptom: status fails when color is ignored. Cause: a green dot. Fix: the checkbox state plus text.
    8. Duplicate ids. Symptom: the wrong field is described. Cause: hard-coded id="note". Fix: useId.
    9. Custom dialog without a trap test. Symptom: tab escapes into the page behind. Cause: role="dialog" on a div. Fix: native showModal().
    10. Injecting model HTML. Symptom: broken semantics and XSS risk. Cause: a string prop rendered as HTML. Fix: text and known components.
    11. Disabled button as the error strategy. Symptom: keyboard users cannot focus the control to learn why. Cause: disabled when the draft is empty and no text explains it. Fix: submit handler plus TextField error.
    12. Axe baseline on new code. Symptom: violations become permanent. Cause: CI allowed a growing list. Fix: zero violations for the design-system tests you add now.

    Knowledge Check

    1. What problem does the design system solve?

    It makes the accessible path the default path. Feature code cannot easily ship an unnamed, unfocusable, color-only control, and model output cannot enter the page as raw HTML. The enterprise failure in the pilot was a control that only a mouse user could see working.

    2. What alternatives exist, and when would you choose each?

    Native HTML is the default. ARIA is for patterns HTML does not cover, and then you owe the keyboard behavior. A well-maintained primitive library can own dialogs if you follow its current documentation; this lesson uses <dialog> so the dependency is the browser. Automated axe is necessary and not a replacement for a keyboard pass. A full manual audit is what you commission for a contractual site-wide claim; this lesson scopes the player controls.

    3. Which boundaries matter?

    The accessibility tree is a public description of the UI: names must be safe to speak. The design-system API is a trust boundary against unsafe markup. The server remains the authorization boundary. Tokens are a visual contract, not a permission system. Client-side hiding of a button is presentation.

    4. What can fail, and how should the system respond?

    A missing name fails review and should fail the role query test. A contrast miss fails the token check before more screens adopt the token. A thrown save from lesson 7 still uses fixed status text, associated if it is a field error. A dialog that does not return focus is a defect in ConfirmDialog, fixed by focusing the opener. Reduced motion is handled in CSS even when JavaScript fails to run the preference logic, because it is a stylesheet.

    5. How would you test?

    getByRole for the button name, the textbox name, and the alert. aria-invalid when error is set. axe on the labeled field inside a main. A manual tab pass from the skip link through save and Escape on the dialog. A negative test that the status message does not include the note body. No claim of full WCAG conformance from this suite alone.

    Interview Questions and Answers

    Q1. What is the first rule of ARIA?

    Do not use ARIA when a native element already has the behavior and semantics. A button is a button. ARIA is for filling gaps, and a role without the keyboard support is a worse failure than no role, because it lies to the accessibility tree.

    Q2. How do you give a form field an accessible name?

    A visible <label htmlFor> pointing at the control id, generated with useId if many instances can mount. Do not rely on placeholder. Do not set a conflicting aria-label.

    Q3. What is the difference between role="status" and role="alert"?

    status is a polite live region for progress such as "Saved." alert is assertive and fits a validation error the user needs now. Using assertive regions for routine updates interrupts people using screen readers.

    Q4. Why is div onClick an accessibility defect even if it is focusable?

    You must reimplement role, keyboard activation, and disabled semantics. Teams usually miss Space or the accessibility tree entry. A button already does this.

    Q5. How does WCAG 2.2 AA treat contrast?

    Normal text needs a contrast ratio of at least 4.5:1, large text at least 3:1, and essential non-text UI boundaries and focus indicators at least 3:1, as the W3C criteria state. Verify with a checker. Do not memorize a homemade ratio.

    Q6. Why can color not be the only indicator?

    Many people cannot distinguish the colors you chose, and some people override colors. Add text or a programmatic state such as a checked checkbox. The complete count in the outline is text; the checkbox state is the programmatic piece.

    Q7. What does showModal() give you that a styled div does not?

    Top-layer modal presentation, inert background in supporting browsers, and Escape to close. You still provide a title, a confirm button, and a cancel button, and you return focus to the opener.

    Q8. How do you test accessibility in CI without claiming a full audit?

    Role-based Testing Library tests plus axe on the design-system components, with zero new violations. Add a short manual keyboard script for the assignment. Say clearly that this does not certify the whole product.

    Q9. How should AI-generated UI enter the codebase?

    As a proposal that a human maps onto Button and TextField, or rejects. Not as HTML assigned to dangerouslySetInnerHTML. Generated labels are strings you review.

    Q10. Why forward refs on React 18 design-system buttons?

    Callers need to restore focus to the real button element. React 18 does not pass ref as a normal prop unless you use forwardRef. Check your React major version before dropping forwardRef.

    Q11. What is wrong with a disabled submit button when the note is empty?

    The control leaves the tab order, so a keyboard user may not discover the rule. Show the field error when they try to save, or provide persistent hint text. disabled fits a pending request, paired with "Saving…" text.

    Q12. How does accessibility interact with authorization?

    They are separate. A control must be usable by people who are allowed to use it. The server must reject people who are not. Making a forbidden action pretty and focusable does not make it allowed. Removing it from the accessibility tree does not make the API safe.

    Assignment

    Problem. Replace the lesson player's ad-hoc controls with the design system in this lesson, and prove the keyboard-named path for note entry and confirmation.

    Tasks.

    1. Add tokens.css with text, surface, danger, and focus tokens. Record the contrast checker result for text on surface and for the focus ring against surface. Adjust tokens until they meet the WCAG 2.2 AA ratios you looked up, not a ratio you invented.
    2. Implement Button with forwardRef, required visible text or an icon-only name, and no className prop.
    3. Implement TextField with useId, label, optional hint, optional error alert, aria-invalid, and aria-describedby.
    4. Implement StatusMessage and a ConfirmDialog that uses showModal(), useId for the title id, and returns focus to the opener.
    5. Use these components in the lesson island. Keep lesson 7's deny-by-default action. Status text stays the fixed string and does not include the note.
    6. Add a skip link to #main in the root layout.
    7. Add Testing Library tests for the button name, the textbox name, and the alert association. Add one axe test if jest-axe is installed. If you cannot install it, say so and run the keyboard script instead.
    8. Write a half-page note: tab order you observed, one defect you fixed, and why model HTML is still rejected.

    Deliverable. Source, tests, contrast notes, and the keyboard note. No secrets. No injected HTML API.

    Challenge. A future model proposes a full outline component as a string. Describe the review pipeline that turns that proposal into props for LessonOutline and Button, the tests that would fail if a div button slipped in, and the security reason you will not render the string. Multi-tenant theming may override tokens, not roles or names. Tenant CSS must not remove :focus-visible.

    Rubric. Conceptual accuracy and semantics 20%. Components and integration 25%. Security of names, errors, and HTML refusal, plus privacy of status text 20%. Automated tests and the manual keyboard note 20%. Contrast evidence and decision write-up 15%.

    Lesson Summary

    The TechLearningPro player is accessible when the accessibility tree tells the truth: buttons are buttons, fields have names, errors are text associated with those fields, focus is visible, and async results are announced without dumping the note into a live region. Tokens carry color and the focus ring. The design system is the gate that feature code and model output both have to pass. WCAG 2.2 AA is the bar for the criteria you touch; a component test suite is evidence, not a certificate.

    Backend Engineering with Node.js builds the service behind the fixture. The UI contract you just wrote stays: the server may change, and the controls still need names. The React course and the Next.js course remain the runtime references. When a later lesson streams model text into this island, it arrives as a string prop on these components.

    Further Reading

    Ready to mark this lesson complete?Track your journey across the entire course.