# Date picker

- **[Atoms](/components/)**

A date field you can type or pick: the text takes ISO or day-first, the button opens the calendar in a dialog.

## When to use

- **Use for**: A date in a form: arrival, departure, a birthday, a due date.
- **Not for**: A time of day or a range in one control. Use two Date pickers.
- **Pairs with**: Field, Calendar, Button.

## Preview

date-picker.tsx

```
import { Theme } from '@/components/klarhimmel/theme/style';
import { DatePicker } from '@/components/klarhimmel/ui/date-picker';
import { Field } from '@/components/klarhimmel/ui/input';

export default function Example() {
  return (
    <Theme theme="brand">
      <Field label="Arrival">
        {(p) => <DatePicker {...p} defaultValue="2026-11-20" today="2026-11-16" />}
      </Field>
    </Theme>
  );
}
```

## Import

- **CLI**

  ```
  npx shadcn add @klarhimmel/date-picker @klarhimmel/input
  ```
- **Import**

  ```
  import { DatePicker } from '@/components/klarhimmel/ui/date-picker';
  ```

- **Files**: date-picker.tsx, input.tsx, in components/klarhimmel/ui/. With it: button, calendar, editing, input-group and 3 more. npm: lucide-react.
- **Render in**: Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
- **Limit**: Overlays render into the Theme root with position: fixed. A transform on an ancestor re-parents fixed (a dialog centres in the wrapper) and overflow: hidden clips menus. Render <Theme> at the app root, outside any transformed wrapper.

## Examples

- **Preselected**

  ```
  import { useState } from 'react';
  import { DatePicker } from '@/components/klarhimmel/ui/date-picker';
  import { Field } from '@/components/klarhimmel/ui/input';
  
  export default function DatePickerPreselected() {
    const [arrival, setArrival] = useState('2026-11-20');
    return (
      <div className="flex min-h-96 w-[min(24rem,calc(100cqw-3rem))] flex-col gap-3">
        <Field label="Arrival" hint="Opens on the chosen day. Clear the text to start over.">
          {(p) => <DatePicker {...p} value={arrival} onValueChange={setArrival} today="2026-11-16" />}
        </Field>
        <p role="status" className="text-kh-small text-kh-muted">{arrival ? `Arriving ${arrival}.` : 'No date: the calendar opens on the current month.'}</p>
      </div>
    );
  }
  ```
- **Limits**

  ```
  import { DatePicker } from '@/components/klarhimmel/ui/date-picker';
  import { Field } from '@/components/klarhimmel/ui/input';
  
  export default function DatePickerLimits() {
    return (
      <div className="flex min-h-96 w-[min(24rem,calc(100cqw-3rem))] flex-col gap-4">
        <Field label="Check-in" hint="The next six weeks. Try typing 2027-01-01.">
          {(p) => <DatePicker {...p} defaultValue="2026-11-20" min="2026-11-16" max="2026-12-27" today="2026-11-16" />}
        </Field>
        <Field label="Birthday (disabled)">
          {(p) => <DatePicker {...p} defaultValue="1988-05-04" disabled />}
        </Field>
      </div>
    );
  }
  ```
- **Invalid, with an error message**

  ```
  import { useState } from 'react';
  import { DatePicker } from '@/components/klarhimmel/ui/date-picker';
  import { Field } from '@/components/klarhimmel/ui/input';
  
  export default function DatePickerInvalid() {
    const [arrival, setArrival] = useState('');
    return (
      <div className="flex min-h-96 w-[min(24rem,calc(100cqw-3rem))] flex-col gap-3">
        <Field label="Arrival" error={arrival ? undefined : 'Choose an arrival date.'}>
          {(p) => <DatePicker {...p} value={arrival} onValueChange={setArrival} invalid={!arrival} today="2026-11-16" />}
        </Field>
        <p role="status" className="text-kh-small text-kh-muted">{arrival ? `Arriving ${arrival}: the error is gone.` : 'The field is invalid until a day is chosen.'}</p>
      </div>
    );
  }
  ```
- **Disabled**

  ```
  import { DatePicker } from '@/components/klarhimmel/ui/date-picker';
  import { Field } from '@/components/klarhimmel/ui/input';
  
  export default function DatePickerDisabled() {
    return (
      <div className="flex w-[min(24rem,calc(100cqw-3rem))] flex-col gap-4">
        <Field label="Arrival" hint="Locked: the booking has been confirmed.">
          {(p) => <DatePicker {...p} defaultValue="2026-11-20" disabled today="2026-11-16" />}
        </Field>
        <Field label="Departure (not set)">
          {(p) => <DatePicker {...p} disabled today="2026-11-16" />}
        </Field>
      </div>
    );
  }
  ```
- **Form**

  ```
  import { useState } from 'react';
  import { Button } from '@/components/klarhimmel/ui/button';
  import { DatePicker } from '@/components/klarhimmel/ui/date-picker';
  import { Field } from '@/components/klarhimmel/ui/input';
  
  export default function DatePickerForm() {
    const [arrival, setArrival] = useState('2026-11-20');
    const [departure, setDeparture] = useState('');
    const [sent, setSent] = useState('');
    return (
      <form
        onSubmit={(e) => {
          e.preventDefault();
          setSent(new URLSearchParams(new FormData(e.currentTarget) as unknown as Record<string, string>).toString());
        }}
        className="flex min-h-[28rem] w-[min(24rem,calc(100cqw-3rem))] flex-col gap-4"
      >
        <Field label="Arrival">
          {(p) => <DatePicker {...p} name="arrival" value={arrival} onValueChange={(v) => { setArrival(v); if (departure && v && departure <= v) setDeparture(''); }} today="2026-11-16" min="2026-11-16" />}
        </Field>
        <Field label="Departure" hint="Must be after arrival.">
          {(p) => <DatePicker {...p} name="departure" value={departure} onValueChange={setDeparture} today="2026-11-16" min={arrival ? new Date(Date.parse(`${arrival}T00:00:00Z`) + 86400000).toISOString().slice(0, 10) : '2026-11-17'} />}
        </Field>
        <Button type="submit" disabled={!arrival || !departure}>Search rooms</Button>
        <p role="status" className="break-all text-kh-small text-kh-muted">{sent ? `Sent: ${sent}` : 'The form posts both days as ISO text.'}</p>
      </form>
    );
  }
  ```

## Props

- **value**: The chosen day, "YYYY-MM-DD", or "" for none.
- **defaultValue**: The day as 'YYYY-MM-DD'; '' means none. Typed text is read on Enter and when leaving the field.
- **onValueChange**: The day as 'YYYY-MM-DD'; '' means none. Typed text is read on Enter and when leaving the field.
- **name**: Submits the chosen day, as "YYYY-MM-DD", with a form (a hidden input).
- **id**
- **placeholder**: Shown while the field is empty.
- **disabled**: Error styling; switches it off. Unreadable text is marked invalid on its own.
- **invalid**: Error styling; switches it off. Unreadable text is marked invalid on its own.
- **aria-label**: Needed when no Field or <label htmlFor> names it.
- **aria-labelledby**: Needed when no Field or <label htmlFor> names it.
- **aria-describedby**
- **labels**: Words for the button, the panel, the calendar's buttons and the two messages. Pass them translated.
- **className**: Extra classes, merged after the component's own.
- **min**: The earliest and latest day that can be chosen. Other days are shown but cannot be picked.
- **max**: Days that cannot be chosen. Typing one is marked and explained in words.
- **isDisabled**: Days that cannot be chosen. Typing one is marked and explained in words.
- **today**: Today, "YYYY-MM-DD". Marked with a ring and the word. Never read from the clock here, so it renders the same on the server.
- **firstDay**: Passed to the calendar.
- **locale**: Passed to the calendar.

## Accessibility

- Type · 2026-11-16 or day first, 16/11/2026
- Enter / leaving the field · Reads the text; wrong text is marked and explained
- Alt+Down on the field · Opens the calendar
- Enter / Space on the button · Opens the calendar on the chosen day
- Escape · Closes it and returns focus to the button
- Arrow keys, Page Up / Down · Move within the calendar (see Calendar)

[Accessibility](/get-started/accessibility)

The WAI-ARIA date picker dialog. Choosing a day closes it and puts the ISO text in the field. A form gets the day as YYYY-MM-DD.

[Previous](/components/calendar)

[Next](/components/command)
