# Keyboard and accessibility

> How the scheduler exposes its structure to assistive technology, how keyboard users select, move, resize and remove events, and what to keep in mind when you customize it.

The scheduler follows the WAI-ARIA grid pattern, like Birch UI Grid. Everything a pointer user can do to an event, a keyboard user can do too, and screen readers hear each event as its title, its time span and its resource.

## Structure

| Element | Role and attributes |
| --- | --- |
| Scrollable body | `role="grid"`, or `role="treegrid"` when resources are nested with `parentId`. Carries `aria-label` (from the `ariaLabel` option, "Resource schedule" by default), `aria-rowcount`, `aria-colcount` and `aria-readonly` when `readOnly` is set. |
| Header | Column headers for each resource column and one for the timeline, labelled "Timeline" followed by the visible date range. The individual tick labels are hidden from assistive technology so they are not read one by one. |
| Resource row | `role="row"` with `aria-rowindex`. Nested rows add `aria-level`, and group rows add `aria-expanded`. |
| Timeline cell | `role="gridcell"` labelled "Schedule for Amira Haddad". |
| Expand toggle | A button labelled "Expand North depot" or "Collapse North depot". |
| Event bar | `role="button"` with an `aria-label` such as "Boiler service, Mon 8:00 AM to 10:30 AM, Amira Haddad". The selected event has `aria-current="true"`. |

`aria-rowcount` and `aria-rowindex` always describe the full list of resources, even though only the visible rows are in the DOM. Screen readers announce "row 12 of 340" correctly while the scheduler virtualizes.

Accessible descriptions are formatted in the scheduler's `locale` and `timeZone`, so a dispatcher planning a Berlin crew hears Berlin times. Give each scheduler on a page a distinct `ariaLabel`, such as "Installation crews, week 50".

## Focus

The scheduler is a single tab stop. Event bars use a roving `tabindex`: one bar is focusable at a time, and the scheduler remembers which one as you move around. When no event is available, the scrollable body itself takes focus. Focus is always visible, drawn with `--lq-sched-focus-ring`.

Selecting an event from code with `selectEvent(id)` or scrolling to it with `scrollToEvent(id)` brings the bar into view, expanding any collapsed group rows that contain it.

## Keyboard

| Key | Action |
| --- | --- |
| <kbd>Tab</kbd> | Move focus into the scheduler and out again. Focus lands on the event focused last, otherwise the selected event, otherwise the first rendered event. |
| Arrow keys, <kbd>Home</kbd>, <kbd>End</kbd> on the scheduler body | Focus the first event in view. |
| <kbd>ArrowLeft</kbd> / <kbd>ArrowRight</kbd> | Focus the previous or next event in the same row, in start-time order. |
| <kbd>ArrowUp</kbd> / <kbd>ArrowDown</kbd> | Focus the event closest in time in the nearest row above or below that has events. |
| <kbd>Home</kbd> / <kbd>End</kbd> | Focus the first or last event in the row. |
| <kbd>Enter</kbd> | Select the focused event and emit `eventClick`, the same as a click. |
| <kbd>Escape</kbd> | Clear the selection. During a pointer drag, cancel the drag. |
| <kbd>Delete</kbd> or <kbd>Backspace</kbd> | Remove the focused event. Focus moves to the next event in the row, or the previous one. |
| <kbd>Alt</kbd> + <kbd>ArrowLeft</kbd> / <kbd>ArrowRight</kbd> | Move the event earlier or later by one snap step. |
| <kbd>Alt</kbd> + <kbd>ArrowUp</kbd> / <kbd>ArrowDown</kbd> | Move the event to the resource row above or below. |
| <kbd>Alt</kbd> + <kbd>Shift</kbd> + <kbd>ArrowLeft</kbd> / <kbd>ArrowRight</kbd> | Shorten or lengthen the event by one snap step, moving its end. |

On macOS, <kbd>Alt</kbd> is the <kbd>Option</kbd> key. Arrow-key navigation covers events inside the scheduler's current range; use `setRange` or your own toolbar to reach other periods.

Tell keyboard users about the editing shortcuts, for example in a help popover next to the scheduler, since they are not discoverable on their own.

## Keyboard editing

Moves, resizes and removals made from the keyboard go through the same path as pointer edits:

- they respect `readOnly`, `draggable: false` and `resizable` (keyboard resizing moves the end edge, so it needs `resizable` to allow `'end'`);
- they snap to the `snap` step, and when `snap` is `false` they use the view preset's own step, so a key press always moves by a meaningful amount;
- they are checked by `validateDrop` and `validateResize`, so your business rules apply to every input method;
- they emit `eventDrop`, `eventResize` and `eventRemove` with `source: 'keyboard'`. Removal has no validator; see [Removing events](https://docs.birchui.com/scheduler/interactions.md#removing-events).

```ts
scheduler.on('eventDrop', ({ event, start, source }) => {
  if (source === 'keyboard') liveRegion.textContent = `${event.title} moved to ${timeFormat.format(start)}`;
});
```

In `readOnly` mode the keyboard still moves focus and selects events, but moving, resizing and removing are turned off.

## Motion, contrast and color

- Transitions run only when the user has not asked for reduced motion (`prefers-reduced-motion`).
- With `theme: 'auto'` the scheduler follows `prefers-color-scheme`.
- In Windows high-contrast mode (`forced-colors`), bars get system-colored borders and the selected bar a system highlight outline, so nothing depends on custom colors.
- Event colors are drawn as a tint with a solid edge, which keeps text contrast stable for any color you choose. Do not rely on color alone to convey status: add a word or an icon with a text alternative in `eventRenderer`.

## Checklist for custom rendering

- Keep `title` meaningful. It is the accessible name of the bar, together with the times and resource.
- Content returned by `eventRenderer` sits inside the bar button. Do not put links, buttons or form fields in it; nested interactive elements are not reachable in the grid pattern. Open details from `eventClick` or `eventDoubleClick` instead.
- Decorative icons should have `aria-hidden="true"`.
- If you replace the default tooltips with `tooltips: (event) => …`, repeat the key facts in the text, because the tooltip is not the accessible name.

```ts
scheduler.update({
  eventRenderer: (job) => {
    const wrapper = document.createElement('span');
    const icon = document.createElement('span');
    icon.className = 'job-icon';
    icon.setAttribute('aria-hidden', 'true');
    const label = document.createElement('span');
    label.textContent = job.priority === 'urgent' ? `Urgent: ${job.title}` : job.title;
    wrapper.append(icon, label);
    return wrapper;
  },
});
```

## Next steps

- [Grid keyboard navigation and accessibility](https://docs.birchui.com/grid/accessibility.md) describes the shared grid pattern in more depth.
- [Event rendering](https://docs.birchui.com/scheduler/event-rendering.md) for custom content and theming tokens.
