Date picker
A compact native date field with a keyboard-navigable month grid in a popover.
pnpm dlx shadcn@latest add @haze/date-picker---
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" />When to use
- A form needs a single date in less space than an inline calendar.
- People may want to browse adjacent days before choosing a date.
When not to use
- The user needs to set both ends of a date range.
Installation
Add the Haze registry to components.json once, then install Date picker with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/date-pickernpx shadcn@latest add @haze/date-pickeryarn dlx shadcn@latest add @haze/date-pickerbunx --bun shadcn@latest add @haze/date-pickerFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Unique field and popover ID prefix. |
| name | string | id | Submitted field name. |
| label | string | Date | Visible native field label. |
| value | string | – | Initial date as YYYY-MM-DD. |
| min | string | – | Earliest selectable date as YYYY-MM-DD. |
| max | string | – | Latest selectable date as YYYY-MM-DD. |
| required | boolean | – | Requires a date for form submission. |
| disabled | boolean | – | Disables the field and its custom picker. |
| form | string | – | ID of an external form. |
| locale | string | en | Locale used for the month grid. |
| weekStart | 0 | 1 | 1 | Shows Sunday or Monday first. |
| openLabel | string | Open calendar | Accessible name for the calendar trigger and panel. |
| class | string | – | Classes on the outer wrapper. |
Keyboard interactions
- Arrow keys
- Move by a day or a week inside the open grid.
- EnterSpace
- Choose the focused day.
- Escape
- Close the calendar without changing the field.
- Space, F4 or AltDown in the field
- Open the calendar.
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.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
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": "http://localhost:4329/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: http://localhost:4329/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.
Dependencies
- @haze/calendar
- @haze/theme (one-time setup)
Source · Original Haze UI work.