# Accessibility

How Zenos preserves semantics and how consumers complete them.

Accessibility is part of the component contract and the product workflow. Zenos provides a reliable foundation, while the consuming application supplies the context that a component library cannot know.

## Responsibility model

```text
Native HTML → semantic foundation
Base UI    → complex keyboard, focus, and ARIA behavior
Zenos      → preserves and composes those semantics
Consumer   → supplies meaningful labels, content, and workflows
```

## What Zenos provides

- Native controls where the browser already provides the correct semantics.
- Base UI behavior for dialogs, menus, selection controls, tabs, and anchored overlays.
- Forwarded refs, native props, event handlers, `aria-*`, and `data-*` attributes.
- Keyboard navigation, focus management, Escape handling, and focus return where applicable.
- Visible focus treatment and semantic `disabled`, `invalid`, and `required` states.
- Field relationships between labels, controls, descriptions, and errors.
- Reduced-motion behavior for transitions and animation.
- Semantic tokens that support readable light and dark themes.

## Consumer responsibilities

<div className="zenos-feature-grid not-content">
  <div className="zenos-feature">
    <strong>Name controls</strong>
    Give icon-only actions, landmarks, forms, and navigation regions concise accessible names.
  </div>
  <div className="zenos-feature">
    <strong>Write useful content</strong>
    Provide meaningful headings, dialog titles, instructions, status messages, and actionable
    errors.
  </div>
  <div className="zenos-feature">
    <strong>Preserve focus</strong>
    Keep a logical order, return focus after overlays close, and never remove an outline without an
    equivalent.
  </div>
  <div className="zenos-feature">
    <strong>Test the workflow</strong>
    Validate complete tasks with keyboard, zoom, assistive technology, real content, and application
    state.
  </div>
</div>

## Start with native semantics

Use a `button` for actions and an anchor for navigation. Keep heading levels meaningful. Use lists, tables, labels, and landmarks for their intended purpose.

Zenos polymorphism does not make every element interchangeable. When using `as`, preserve the semantic role and required native behavior of the resulting element.

## Labels, descriptions, and errors

Use `Field` to establish form relationships:

```tsx
<Field.Root required invalid={hasError}>
  <Field.Label>Email</Field.Label>
  <Field.Control>
    <Input name="email" autoComplete="email" />
  </Field.Control>
  <Field.Description>Used for security notifications.</Field.Description>
  <Field.Error>Enter a valid email address.</Field.Error>
</Field.Root>
```

A placeholder is not a label. Error text should explain how to recover, and invalid state should not rely on color alone.

## Keyboard interaction

Native controls and Base UI primitives provide their established keyboard patterns. Consumers should not replace those handlers unless the product requires a different documented interaction.

Verify at minimum:

- `Tab` and `Shift+Tab` move through controls in a logical order.
- `Enter` and `Space` activate the expected controls.
- `Escape` closes temporary surfaces without closing unrelated parents.
- Arrow keys, Home, and End work where the component pattern defines them.
- Disabled controls are skipped or announced according to their semantics.

## Focus management

Focus must remain visible in light and dark themes. Dialogs and modal sheets contain focus while open and return it to a sensible trigger when closed. Popovers and menus should not leave focus on removed content.

Composition through Base UI's `render` prop must preserve the supplied props, ref, event handlers, and ARIA attributes on the rendered element.

## Content and visual design

- Maintain sufficient contrast for text, icons, borders, and focus rings.
- Do not communicate status with color alone.
- Allow labels, descriptions, and errors to wrap.
- Keep controls reachable at 200% browser zoom.
- Respect `prefers-reduced-motion` and avoid essential information in animation.
- Test right-to-left content and logical navigation where direction matters.
- Provide text alternatives for meaningful images; use empty alt text for decoration.

## Dynamic content

Announce important asynchronous results with an appropriate live region, but avoid narrating every intermediate update. Loading indicators need nearby context when the outcome is not otherwise clear.

Move focus only when it helps the user continue the task. Validation should normally preserve focus and connect the control to its error instead of jumping unexpectedly.

## Testing strategy

Zenos uses several layers because no single tool can verify accessibility:

| Layer                      | Purpose                                                                           |
| -------------------------- | --------------------------------------------------------------------------------- |
| Vitest and Testing Library | Roles, accessible names, state, relationships, and component contracts            |
| Playwright                 | Browser keyboard behavior, focus movement, portals, and complete consumer flows   |
| axe                        | Common automated WCAG failures on representative rendered pages                   |
| Manual review              | Screen readers, zoom, contrast, motion, RTL, long content, and task comprehension |

Use accessible queries such as `getByRole` in tests. They validate the public experience and remain more stable than classes or private selectors.

## Manual checklist

- Complete the flow with keyboard only.
- Verify Tab, Shift+Tab, Enter, Space, Escape, arrows, Home, and End where relevant.
- Confirm focus is always visible and returns after an overlay closes.
- Test at 200% zoom and with large system text.
- Enable reduced motion, dark mode, and RTL.
- Review labels, descriptions, status messages, and errors with a screen reader.
- Test empty, loading, invalid, disabled, and long-content states.
- Confirm touch targets remain usable on a narrow viewport.

Automated checks find common failures; they do not certify an experience or replace testing with disabled users and assistive technology.

Source: https://zenos-ui.pages.dev/foundations/accessibility/