# Date picker

> A compact native date field with a keyboard-navigable month grid in a popover.

- Kind: ui · Category: Forms · Interactivity: script
- Install: `npx shadcn@latest add @haze/date-picker`
- File: `src/components/haze/ui/date-picker.astro`
- npm dependencies: none
- Registry dependencies: @haze/calendar
- Docs page: https://hazeui.com/ui/date-picker

## Use when
- A form needs a single date in less space than an inline calendar.
- People may want to browse adjacent days before choosing a date.

## Avoid when
- The user needs to set both ends of a date range.

## Alternatives
- [calendar](https://hazeui.com/ui/calendar.md)
- [date-range-picker](https://hazeui.com/ui/date-range-picker.md)
- [time-picker](https://hazeui.com/ui/time-picker.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` |  | yes | Unique field and popover ID prefix. |
| name | `string` | id | no | Submitted field name. |
| label | `string` | Date | no | Visible native field label. |
| value | `string` |  | no | Initial date as YYYY-MM-DD. |
| min | `string` |  | no | Earliest selectable date as YYYY-MM-DD. |
| max | `string` |  | no | Latest selectable date as YYYY-MM-DD. |
| required | `boolean` |  | no | Requires a date for form submission. |
| disabled | `boolean` |  | no | Disables the field and its custom picker. |
| form | `string` |  | no | ID of an external form. |
| locale | `string` | en | no | Locale used for the month grid. |
| weekStart | `0 \| 1` | 1 | no | Shows Sunday or Monday first. |
| openLabel | `string` | Open calendar | no | Accessible name for the calendar trigger and panel. |
| class | `string` |  | no | Classes on the outer wrapper. |

## Accessibility
- The native date field remains usable with scripting disabled.
- Opening from the button or the keyboard moves focus into the month grid; clicking the field opens it and keeps focus in the field for typing. Focus returns after choosing a date or pressing Escape.
- The browser's own date popup never opens on top of the calendar.
- Key Arrow keys: Move by a day or a week inside the open grid.
- Key Enter / Space: Choose the focused day.
- Key Escape: Close the calendar without changing the field.
- Key Space, F4 or Alt + Down in the field: Open the calendar.

## Agent prompts

### Install and use

Install the Haze UI component "Date picker" with `npx shadcn@latest add @haze/date-picker`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import DatePicker from "@/components/haze/ui/date-picker.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/date-picker.md

### Customize with real content

Adapt the Haze date-picker ui for our product. Replace the demo values of these props with our real content: id, name, label, value, min, max, required, disabled, form, locale, weekStart, openLabel, class. Keep the layout, the heading level rules and these accessibility details: The native date field remains usable with scripting disabled. Opening from the button or the keyboard moves focus into the month grid; clicking the field opens it and keeps focus in the field for typing. Focus returns after choosing a date or pressing Escape. The browser's own date popup never opens on top of the calendar. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using date-picker, check it fits: use it when a form needs a single date in less space than an inline calendar.; people may want to browse adjacent days before choosing a date.. Avoid it when the user needs to set both ends of a date range.. Alternatives: @haze/calendar, @haze/date-range-picker, @haze/time-picker.

## Example requests that should lead here
- Add a delivery date field that opens a month picker and allows only dates in the booking window.

## Source

```astro
---
import Calendar from "./calendar.astro";

interface Props {
  id: string;
  name?: string;
  label?: string;
  value?: string;
  min?: string;
  max?: string;
  required?: boolean;
  disabled?: boolean;
  form?: string;
  locale?: string;
  weekStart?: 0 | 1;
  openLabel?: string;
  class?: string;
  [key: string]: unknown;
}

const { id, ...props } = Astro.props;
---

<Calendar {...props} id={id} presentation="popover" />
```
