import { Meta } from '@storybook/addon-docs/blocks';

<Meta title="Forms/DateLookup/Accessibility" />

# Accessibility

DateLookup wraps the Calendar component inside a dropdown panel. It provides full keyboard accessibility for opening, navigating, selecting, and dismissing dates.

## Keyboard Support

<table>
  <thead>
    <tr>
      <th>Key</th>
      <th>Context</th>
      <th>Action</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        <code>ArrowLeft/Right/Up/Down</code>
      </td>
      <td>Trigger focused, panel closed</td>
      <td>Opens the panel</td>
    </tr>
    <tr>
      <td>
        <code>ArrowLeft/Right/Up/Down</code>
      </td>
      <td>Panel open</td>
      <td>Navigates between dates (see Calendar)</td>
    </tr>
    <tr>
      <td>
        <code>Enter</code> / <code>Space</code>
      </td>
      <td>Panel open, enabled date focused</td>
      <td>Selects date, closes panel</td>
    </tr>
    <tr>
      <td>
        <code>Enter</code> / <code>Space</code>
      </td>
      <td>Panel open, disabled date focused</td>
      <td>No action (panel stays open)</td>
    </tr>
    <tr>
      <td>
        <code>Escape</code>
      </td>
      <td>Panel open</td>
      <td>Reverts to original value, closes panel</td>
    </tr>
  </tbody>
</table>

<br />

### Click Behaviour

- **Clicking an enabled date**: selects it, closes the panel, fires `onChange`
- **Clicking a disabled date**: does not select, panel stays open, focus remains in the calendar grid

## Screen Reader Announcements

DateLookup relies on the Calendar's built-in accessibility features for date announcements. See [Calendar
Accessibility](?path=/docs/forms-calendar-accessibility--docs) for details on how dates are labelled and described.

### Trigger Button

The trigger button announces the currently selected date (or placeholder text when no date is selected). It uses `aria-controls` to associate with the panel.

### Panel

The dropdown panel is rendered with `role="dialog"` and is connected to the trigger via `aria-controls`. When opened, focus moves into the calendar grid.

## Disabled Dates (via `disabledRules`)

When `disabledRules` is provided, disabled dates remain focusable and keyboard-navigable:

- `aria-disabled="true"` marks the cell as unavailable
- "not available" is appended to the aria-label
- `aria-describedby` links to the InlinePrompt reason text
- Keyboard navigation reaches disabled dates (they are not skipped)
- Clicking or pressing Enter on a disabled date does **not** close the panel

## Out-of-Range Dates (via `min`/`max`)

Dates outside `min`/`max` boundaries use `aria-disabled="true"` (not the native HTML `disabled` attribute). They are rendered as interactive buttons in the grid and can be clicked; the `aria-label` appends "not available". Arrow key navigation clamps at the boundary, so keyboard users cannot navigate into out-of-range cells.

This distinction is intentional: `min`/`max` defines a hard boundary, while `disabledRules` marks dates that exist but are unavailable (users can discover them and understand why via the InlinePrompt).

### InlinePrompt

An InlinePrompt renders below the day grid inside the panel when the visible month contains disabled dates. It displays the configured `disabledRules.reason` text.

The prompt is linked to disabled cells via `aria-describedby`, so screen readers announce the reason when a disabled
date receives focus. See [Calendar Accessibility](?path=/docs/forms-calendar-accessibility--docs) for full details on
the prompt's announcement behaviour.

## Consumer Callbacks

The `onDateSelect` callback fires with `{ date, isEnabled }` whenever the user navigates to or clicks on any date. Consumers can use this to:

- Display a custom message explaining why a specific date is disabled
- Track which dates users attempt to select
- Provide alternative actions for disabled dates
