# Date Time Picker

> A calendar and time popover that picks an instant in a time zone.

```tsx title="hero.tsx"
import {
  DateTimePicker,
  DateTimePickerClear,
  DateTimePickerContent,
  DateTimePickerLabel,
  DateTimePickerTrigger,
} from '@langgenius/dify-ui/date-time-picker'

const defaultPublishAt = new Date('2026-12-15T09:30:00Z')

export function DateTimePickerHeroDemo() {
  return (
    <DateTimePicker timeZone="UTC" defaultValue={defaultPublishAt}>
      <div className="flex w-full max-w-72 flex-col gap-1">
        <DateTimePickerLabel>Publish app at (UTC)</DateTimePickerLabel>
        <div className="flex items-center gap-1">
          <DateTimePickerTrigger className="w-auto min-w-0 flex-1" />
          <div className="size-8 shrink-0">
            <DateTimePickerClear aria-label="Clear publish time" />
          </div>
        </div>
      </div>
      <DateTimePickerContent />
    </DateTimePicker>
  )
}
```

## Usage guidelines

- Use `DateTimePicker` for an instant (`Date`) shown in an IANA time zone, such as a scheduled publish time. Use `DatePicker` for a civil date `YYYY-MM-DD` and `TimePicker` for a wall time `HH:mm`. The pickers do not accept typed text.
- `timeZone` is required and controls display, editing and Now. The value stays an instant and submits as an ISO 8601 UTC string. Parse API payloads and convert business values outside the picker.
- **Name the field at the call site**: prefer one visible picker Label. It names both the trigger and the popup through `aria-labelledby`, and clicking its text focuses the trigger without opening it. A Label with `className="sr-only"` names a compact field without visible text. `FieldLabel nativeLabel={false} render={<div />}` also works. Do not point a native `label[for]` at the trigger: activating it clicks the button.
- Without a Label, name the trigger and the content with `aria-label` or `aria-labelledby`. The trigger's name appends its visible value (or placeholder) to label text; an explicit `aria-label` replaces the whole name, so include the visible value in it. Put meaningful annotations inside the Value part so they join the name.
- **Name Clear explicitly**: Clear follows the `IconButton` naming contract, so give it an `aria-label` such as "Clear start date". Place it next to the trigger, never inside the trigger button.
- Use `defaultValue`, or `value` with `onValueChange`, and keep that choice for the field's lifetime. `null` means empty, and Clear emits `null`. `details.reason` is `item-press`, `clear-press` or `reset`; `details.cancel()` rejects that change and its follow-up close. Unchanged values do not emit again.
- Edits in the popup, including Now, stay in a draft until OK. Switching between the date and time views keeps the draft. Close, `Escape` and an outside press discard it, and reopening starts from the committed value. Changing the controlled value or `timeZone` starts a fresh draft.
- Restrict the date with `minDate`, `maxDate` (both `YYYY-MM-DD` in `timeZone`) and `isDateUnavailable`, and the time with `isTimeUnavailable`, which receives the wall date and time. Unavailable drafts stay reachable, but OK is disabled and the reason is announced.
- The picker edits whole minutes. It rejects a wall time skipped by daylight saving, keeps an unchanged instant during a repeated hour, and resolves an edited repeated time to the earlier instant.
- `hourCycle` switches between 12-hour (default) and 24-hour display.
- Content keeps its natural height and flips above or below the trigger; it does not shrink on small screens. Pass `maxHeight` only to opt into scrolling the body while the actions stay visible.
- `locale` takes a DayPicker locale object and changes formatting and digits, not the calendar system or the stored value. Translate action labels through `labels`, plus placeholders, `requiredLabel` and `validationMessage`. Direction comes from the nearest `DirectionProvider`; for a local RTL region, also set `dir` on the wrapper and on the content.
- With `name`, the committed value joins native `FormData`, and an empty field submits `''`. Inside a `Field`, `Field.name` takes precedence, `validate` receives the domain value, and `Form.onFormSubmit` receives the same strings as `FormData`. Required and invalid fields block submission and focus the first invalid trigger. Reset restores `defaultValue`. Disabled fields are left out; read-only fields open for browsing and still submit.

## Anatomy

```tsx
import {
  DateTimePicker,
  DateTimePickerClear,
  DateTimePickerContent,
  DateTimePickerLabel,
  DateTimePickerTrigger,
  DateTimePickerValue,
} from '@langgenius/dify-ui/date-time-picker'
```

```tsx
<DateTimePicker timeZone="UTC">
  <DateTimePickerLabel />
  <DateTimePickerTrigger>
    <DateTimePickerValue />
  </DateTimePickerTrigger>
  <DateTimePickerClear />
  <DateTimePickerContent />
</DateTimePicker>
```

`DateTimePickerTrigger` is a native button whose default children are the Value and a decorative calendar icon. When you replace them, include exactly one `DateTimePickerValue` and keep the trailing calendar icon; its render callback receives the formatted text, not the raw value. `DateTimePickerContent` owns the portal, initial focus, calendar, columns and actions.

## Examples

### Time zone

The same instant reads differently in each zone. Changing `timeZone` changes what the trigger shows, not the stored `Date`. The zone suffix lives inside `DateTimePickerValue`, so it is part of the trigger's name.

```tsx title="time-zone.tsx"
import {
  DateTimePicker,
  DateTimePickerContent,
  DateTimePickerLabel,
  DateTimePickerTrigger,
  DateTimePickerValue,
} from '@langgenius/dify-ui/date-time-picker'
import {
  Select,
  SelectContent,
  SelectItem,
  SelectItemIndicator,
  SelectItemText,
  SelectLabel,
  SelectTrigger,
  SelectValue,
} from '@langgenius/dify-ui/select'
import * as React from 'react'

const timeZones = [
  { label: 'UTC', value: 'UTC' },
  { label: 'New York', value: 'America/New_York' },
  { label: 'Berlin', value: 'Europe/Berlin' },
  { label: 'Tokyo', value: 'Asia/Tokyo' },
]

const defaultExpiresAt = new Date('2026-12-20T23:00:00Z')

export function DateTimePickerTimeZoneDemo() {
  const [timeZone, setTimeZone] = React.useState('America/New_York')
  const [expiresAt, setExpiresAt] = React.useState<Date | null>(defaultExpiresAt)
  const zoneLabel = timeZones.find((zone) => zone.value === timeZone)?.label

  return (
    <div className="flex w-full max-w-72 flex-col gap-4">
      <Select
        items={timeZones}
        value={timeZone}
        onValueChange={(value) => {
          if (value) setTimeZone(value)
        }}
      >
        <div className="flex flex-col gap-1">
          <SelectLabel>Workspace time zone</SelectLabel>
          <SelectTrigger className="w-full">
            <SelectValue />
          </SelectTrigger>
        </div>
        <SelectContent>
          {timeZones.map((zone) => (
            <SelectItem key={zone.value} value={zone.value}>
              <SelectItemText>{zone.label}</SelectItemText>
              <SelectItemIndicator />
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
      <DateTimePicker timeZone={timeZone} value={expiresAt} onValueChange={setExpiresAt}>
        <div className="flex flex-col gap-1">
          <DateTimePickerLabel>Share link expires at</DateTimePickerLabel>
          <DateTimePickerTrigger className="w-full">
            <DateTimePickerValue className="min-w-0 truncate">
              {(value) => (
                <React.Fragment>
                  {value} <span className="text-text-tertiary">{zoneLabel}</span>
                </React.Fragment>
              )}
            </DateTimePickerValue>
            <span
              aria-hidden="true"
              className="i-ri-calendar-line size-4 shrink-0 text-text-tertiary"
            />
          </DateTimePickerTrigger>
        </div>
        <DateTimePickerContent />
      </DateTimePicker>
      <p aria-live="polite" className="system-xs-regular break-all text-text-tertiary tabular-nums">
        Stored instant: {expiresAt?.toISOString() ?? 'null'}
      </p>
    </div>
  )
}
```

### Available dates and times

`minDate` and `maxDate` bound the calendar in the picker's zone, and `isTimeUnavailable` rules out late-night sends.

```tsx title="constraints.tsx"
import {
  DateTimePicker,
  DateTimePickerContent,
  DateTimePickerLabel,
  DateTimePickerTrigger,
} from '@langgenius/dify-ui/date-time-picker'
import * as React from 'react'

const defaultCampaignAt = new Date('2026-12-14T14:00:00Z')

export function DateTimePickerConstraintsDemo() {
  const hintId = React.useId()

  return (
    <DateTimePicker
      timeZone="Asia/Shanghai"
      hourCycle={24}
      defaultValue={defaultCampaignAt}
      minDate="2026-12-01"
      maxDate="2026-12-31"
      isTimeUnavailable={({ time }) => time < '08:00' || time >= '23:00'}
    >
      <div className="flex w-full max-w-64 flex-col gap-1">
        <DateTimePickerLabel>Send campaign at (Shanghai)</DateTimePickerLabel>
        <DateTimePickerTrigger className="w-full" aria-describedby={hintId} />
        <p id={hintId} className="system-xs-regular text-text-tertiary">
          December 2026 only, 08:00–22:59 Shanghai time.
        </p>
      </div>
      <DateTimePickerContent />
    </DateTimePicker>
  )
}
```

### Native form

With `name`, the picker submits the instant as an ISO 8601 UTC string. A required empty field blocks submission and focuses its trigger.

```tsx title="form.tsx"
import { Button } from '@langgenius/dify-ui/button'
import {
  DateTimePicker,
  DateTimePickerContent,
  DateTimePickerLabel,
  DateTimePickerTrigger,
} from '@langgenius/dify-ui/date-time-picker'
import * as React from 'react'

export function DateTimePickerFormDemo() {
  const [submitted, setSubmitted] = React.useState('')

  return (
    <form
      aria-label="Schedule batch run"
      className="flex w-full max-w-72 flex-col gap-4"
      onSubmit={(event) => {
        event.preventDefault()
        setSubmitted(JSON.stringify(Object.fromEntries(new FormData(event.currentTarget))))
      }}
      onReset={() => setSubmitted('')}
    >
      <DateTimePicker
        name="startAt"
        timeZone="UTC"
        required
        validationMessage="Choose when the batch run starts."
      >
        <div className="flex flex-col gap-1">
          <DateTimePickerLabel>Batch run starts at (UTC)</DateTimePickerLabel>
          <DateTimePickerTrigger className="w-full" />
        </div>
        <DateTimePickerContent />
      </DateTimePicker>
      <div className="flex gap-2">
        <Button type="submit" variant="primary">
          Schedule
        </Button>
        <Button type="reset" variant="secondary">
          Reset
        </Button>
      </div>
      {submitted && (
        <p
          aria-live="polite"
          className="system-xs-regular break-all text-text-tertiary tabular-nums"
        >
          Submitted: {submitted}
        </p>
      )}
    </form>
  )
}
```

## Keyboard

| Key                                      | Action                                                                                                                                                                            |
| ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Enter`, `Space`                         | Opens the popup from the trigger and focuses the selected day.                                                                                                                    |
| `ArrowLeft`, `ArrowRight`                | In the calendar, moves focus one day, skipping unavailable days and crossing into adjacent months. Reversed in right-to-left.                                                     |
| `ArrowUp`, `ArrowDown`                   | In the calendar, moves focus one week. In a time column, selects the previous or next option, stopping at the ends.                                                               |
| `PageUp`, `PageDown`                     | In the calendar, moves focus one month. In a time column, moves the selection five options.                                                                                       |
| `Shift` + `PageUp`, `Shift` + `PageDown` | In the calendar, moves focus one year.                                                                                                                                            |
| `Home`, `End`                            | In the calendar, moves focus to the start or end of the week. In a time column, selects the first or last option.                                                                 |
| Digits                                   | In a time column, selects the option that starts with the typed number.                                                                                                           |
| `Enter`, `Space`                         | On a day, selects it in the draft. On Pick Time or Pick Date, switches the view and keeps the draft. On OK, commits the draft, closes the popup and returns focus to the trigger. |
| `Tab`                                    | Moves between the view's controls and the actions, wrapping inside the popup.                                                                                                     |
| `Escape`                                 | Discards the draft, closes the popup and returns focus to the trigger.                                                                                                            |

The month and year selector in the date view works as in `DatePicker`: `ArrowUp` and `ArrowDown` move one option, `PageUp` and `PageDown` move five, `Home` and `End` reach the ends, digits locate a year and letters locate a month. `Escape` discards the selection and returns focus to the month title.

## API reference

### DateTimePicker

Groups all parts of a date-and-time picker storing a `Date` instant formatted in `timeZone`. Doesn't render its own HTML element.

Popup edits stay in a draft until confirmed with the apply button; also commits on clearing or form reset.

**Props**

| Prop                 | Type                                                                         | Default      | Description                                                                                                                                                                                                               |
| -------------------- | ---------------------------------------------------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `placeholder?`       | `string`                                                                     | —            | The text shown in the trigger when no value is selected.                                                                                                                                                                  |
| `disabled?`          | `boolean`                                                                    | `false`      | Whether the component should ignore user interaction.                                                                                                                                                                     |
| `readOnly?`          | `boolean`                                                                    | `false`      | Whether the user should be unable to change the value.                                                                                                                                                                    |
| `required?`          | `boolean`                                                                    | `false`      | Whether the user must choose a value before submitting a form.                                                                                                                                                            |
| `requiredLabel?`     | `string`                                                                     | `'Required'` | Visually hidden text that announces the field as required.                                                                                                                                                                |
| `invalid?`           | `boolean`                                                                    | `false`      | Whether to mark the value as invalid regardless of native validation.                                                                                                                                                     |
| `name?`              | `string`                                                                     | —            | Identifies the field when a form is submitted.                                                                                                                                                                            |
| `form?`              | `string`                                                                     | —            | Identifies the form that owns the hidden input. Useful when the picker is rendered outside the form.                                                                                                                      |
| `validationMessage?` | `string`                                                                     | —            | The error message reported when `invalid` is set or a required value is missing. Falls back to `'Choose a valid value.'` and `'Choose a value.'` respectively; an unavailable value reports `labels.unavailable` instead. |
| `onOpenChange?`      | `((open: boolean, details: PickerOpenChangeDetails) => void)`                | —            | Event handler called when the popup is opened or closed.                                                                                                                                                                  |
| `children`           | `React.ReactNode`                                                            | —            | The picker parts.                                                                                                                                                                                                         |
| `locale?`            | `Partial<DayPickerLocale>`                                                   | —            | The `@daypicker/react` locale used for month names, weekdays, and the first day of the week. Defaults to US English.                                                                                                      |
| `minDate?`           | `string`                                                                     | —            | The earliest selectable date, as `YYYY-MM-DD`.                                                                                                                                                                            |
| `maxDate?`           | `string`                                                                     | —            | The latest selectable date, as `YYYY-MM-DD`.                                                                                                                                                                              |
| `isDateUnavailable?` | `((date: string) => boolean)`                                                | —            | Returns `true` for a `YYYY-MM-DD` date that cannot be selected.                                                                                                                                                           |
| `hourCycle?`         | `12 \| 24`                                                                   | `12`         | Whether hours are shown on a 12-hour clock with AM and PM, or a 24-hour clock.                                                                                                                                            |
| `value?`             | `Date \| null`                                                               | —            | The controlled value, an instant displayed in `timeZone`; `null` represents an empty field. To render an uncontrolled date-time picker, use the `defaultValue` prop instead.                                              |
| `defaultValue?`      | `Date \| null`                                                               | `null`       | The uncontrolled value when the picker is initially rendered. To render a controlled date-time picker, use the `value` prop instead.                                                                                      |
| `onValueChange?`     | `((value: Date \| null, details: DateTimePickerChangeEventDetails) => void)` | —            | Called on OK, clearing or form reset; popup draft edits do not emit changes.                                                                                                                                              |
| `timeZone`           | `string`                                                                     | —            | The IANA time zone used to display and edit the value, such as `'Asia/Shanghai'`.                                                                                                                                         |
| `isTimeUnavailable?` | `((wall: Readonly<ZonedWallTime>) => boolean)`                               | —            | Returns `true` for a wall-clock time in `timeZone` that cannot be selected.                                                                                                                                               |
| `labels?`            | `Partial<DateTimePickerLabels>`                                              | —            | Text for the built-in controls and messages, usually translated strings. Missing entries fall back to English.                                                                                                            |

Inherits `defaultOpen`, `open` from [Base UI Popover.Root](https://base-ui.com/react/components/popover#root).

### DateTimePickerClear

A button component that can be used to trigger actions. Renders a `<button>` element.

**Props**

| Prop               | Type                                                                                                     | Default     | Description                                                                                          |
| ------------------ | -------------------------------------------------------------------------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------- |
| `aria-label?`      | `string`                                                                                                 | —           | Names the element for assistive technology. Pass either this or `aria-labelledby`.                   |
| `aria-labelledby?` | `string`                                                                                                 | —           | Identifies the element that names this one. Pass either this or `aria-label`.                        |
| `variant?`         | `'default' \| 'ghost' \| 'ghost-accent' \| 'primary' \| 'secondary' \| 'secondary-accent' \| 'tertiary'` | `'default'` | The visual emphasis of the button. The accent variants cannot be combined with `tone="destructive"`. |
| `tone?`            | `'default' \| 'destructive'`                                                                             | `'default'` | Whether the button represents a destructive action.                                                  |
| `ref?`             | `React.Ref<HTMLButtonElement>`                                                                           | —           | —                                                                                                    |

Valid prop combinations:

- `aria-label: string`, `aria-labelledby?: undefined`, `variant?: 'default' | 'ghost' | 'primary' | 'secondary' | 'tertiary'`, `tone?: 'default' | 'destructive'`
- `aria-label: string`, `aria-labelledby?: undefined`, `variant: 'ghost-accent' | 'secondary-accent'`, `tone?: 'default'`
- `aria-label?: undefined`, `aria-labelledby: string`, `variant?: 'default' | 'ghost' | 'primary' | 'secondary' | 'tertiary'`, `tone?: 'default' | 'destructive'`
- `aria-label?: undefined`, `aria-labelledby: string`, `variant: 'ghost-accent' | 'secondary-accent'`, `tone?: 'default'`

Inherits `className`, `style`, `focusableWhenDisabled` from [Base UI Button](https://base-ui.com/react/components/button).

**Data attributes**

| Attribute       | Description                          |
| --------------- | ------------------------------------ |
| `data-disabled` | Present when the button is disabled. |

### DateTimePickerContent

A container for the popover contents. Renders a `<div>` element.

**Props**

| Prop          | Type                           | Default   | Description                                                                                             |
| ------------- | ------------------------------ | --------- | ------------------------------------------------------------------------------------------------------- |
| `sideOffset?` | `number \| OffsetFunction`     | `8`       | Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance. |
| `align?`      | `'center' \| 'end' \| 'start'` | `'start'` | How to align the popup relative to the specified side.                                                  |

Inherits `className`, `style`, `side`, `alignOffset`, `finalFocus` from [Base UI Popover.Popup](https://base-ui.com/react/components/popover#popup).

**Data attributes**

| Attribute             | Description                                                           |
| --------------------- | --------------------------------------------------------------------- |
| `data-open`           | Present when the popup is open.                                       |
| `data-closed`         | Present when the popup is closed.                                     |
| `data-starting-style` | Present when the popup begins animating in.                           |
| `data-ending-style`   | Present when the popup is animating out.                              |
| `data-side`           | Indicates which side the popup is positioned relative to the trigger. |
| `data-align`          | Indicates how the popup is aligned relative to specified side.        |
| `data-instant`        | Present if animations should be instant.                              |

**CSS variables**

| Variable         | Type | Description              |
| ---------------- | ---- | ------------------------ |
| `--popup-width`  | —    | The width of the popup.  |
| `--popup-height` | —    | The height of the popup. |

### DateTimePickerLabel

Inherits `className`, `style` from [Base UI null](https://base-ui.com/react/handbook/composition).

**Data attributes**

| Attribute       | Description                                                      |
| --------------- | ---------------------------------------------------------------- |
| `data-disabled` | Present when the component should ignore user interaction.       |
| `data-touched`  | Present when the field has been touched.                         |
| `data-dirty`    | Present when the field value has changed from its initial value. |
| `data-filled`   | Present when the field has a value.                              |
| `data-focused`  | Present when the field is focused.                               |

### DateTimePickerTrigger

A button that opens the popover. Renders a `<button>` element.

**Props**

| Prop   | Type                           | Default | Description |
| ------ | ------------------------------ | ------- | ----------- |
| `ref?` | `React.Ref<HTMLButtonElement>` | —       | —           |

Inherits `id`, `className`, `style` from [Base UI Popover.Trigger](https://base-ui.com/react/components/popover#trigger).

**Data attributes**

| Attribute         | Description                                     |
| ----------------- | ----------------------------------------------- |
| `data-readonly`   | Present when the picker is read-only.           |
| `data-required`   | Present when the picker requires a value.       |
| `data-popup-open` | Present when the corresponding popover is open. |
| `data-pressed`    | Present when the trigger is pressed.            |
| `data-disabled`   | Present when the trigger is disabled.           |

### DateTimePickerValue

**Props**

| Prop        | Type                                                             | Default | Description                                                            |
| ----------- | ---------------------------------------------------------------- | ------- | ---------------------------------------------------------------------- |
| `children?` | `((displayValue: string) => React.ReactNode) \| React.ReactNode` | —       | Receives the formatted committed value, or the placeholder when empty. |
