SwiftUI.js
Components

DatePicker

DatePicker is a native `<input>`-backed control for selecting dates and times. It keeps standard form semantics, browser validation, and keyboard behavior.

DatePicker is a native `<input>`-backed control for selecting dates and times. It keeps standard form semantics, browser validation, and keyboard behavior.

Examples

Basic Usage

Preview unavailable for this example in the static docs build.

Show code
const ControlledDateDemo = () => {
  const [date, setDate] = useState('2026-04-10')
  return (
    <VStack spacing={16}>
      <Text>Selected: {date}</Text>
      <DatePicker
        aria-label="Controlled date"
        selection={date}
        onSelectionChange={setDate}
        mode="date"
      />
    </VStack>
  )
}

Uncontrolled Usage

Preview unavailable for this example in the static docs build.

Show code
const UncontrolledTimeDemo = () => {
  return (
    <VStack spacing={16}>
      <DatePicker
        aria-label="Meeting time"
        defaultValue="09:30"
        mode="time"
      />
      <Text>Use the browser-native time picker input.</Text>
    </VStack>
  )
}

Date and Time

Preview unavailable for this example in the static docs build.

Show code
const DateAndTimeDemo = () => {
  const [value, setValue] = useState('2026-04-10T09:30')
  return (
    <VStack spacing={16}>
      <Text>Selected: {value}</Text>
      <DatePicker
        aria-label="Scheduled start"
        selection={value}
        onSelectionChange={setValue}
        mode="dateAndTime"
      />
    </VStack>
  )
}

SwiftUI-Style Components

Preview unavailable for this example in the static docs build.

Show code
const DisplayedComponentsDemo = () => {
  const [value, setValue] = useState('2026-04-10T09:30')
  return (
    <VStack spacing={16}>
      <Text>Selected: {value}</Text>
      <DatePicker
        aria-label="SwiftUI-style schedule"
        selection={value}
        onSelectionChange={setValue}
        displayedComponents={['date', 'hourAndMinute']}
      />
    </VStack>
  )
}

Minute Interval

Preview unavailable for this example in the static docs build.

Show code
<DatePicker
      aria-label="Quarter-hour time"
      defaultValue="09:30"
      minuteInterval={15}
      mode="time"
    />

API

PropTypeRequiredDescription
selectionstringNoSwiftUI-style alias for the current native input value.
valuestringNoThe current native input value.
defaultSelectionstringNoSwiftUI-style alias for the initial uncontrolled value.
defaultValuestringNoThe initial native input value when uncontrolled.
onChangeChangeEventHandler<HTMLInputElement>NoNative input change handler.
onSelectionChange(value: string) => voidNoSwiftUI-style value-first change handler.
onValueChange(value: string) => voidNoValue-first change handler for SwiftUI-style ergonomics.
minstringNoThe minimum selectable value, expressed in the same native input format as `value`.
maxstringNoThe maximum selectable value, expressed in the same native input format as `value`.
minimumDatestringNoBackward-compatible minimum alias for SwiftUI-style callers.
maximumDatestringNoBackward-compatible maximum alias for SwiftUI-style callers.
modeDatePickerModeNoThe display mode of the date picker. Default: 'date'
displayedComponentsDatePickerDisplayedComponent[]NoSwiftUI-style displayed components. When provided, these values determine the native input type.
minuteIntervalnumberNoSwiftUI-style minute granularity for time-based pickers.
disabledbooleanNoWhether the date picker is disabled. Default: false

Inherits additional props from Omit< IBaseElementComponent<'input'>, 'type' | 'value' | 'defaultValue' | 'onChange' | 'children' | 'min' | 'max' >.

Overview

DatePicker is a native <input>-backed control for selecting dates and times. It keeps standard form semantics, browser validation, and keyboard behavior.

SwiftUI Correspondence: Similar to SwiftUI's DatePicker.

Notes

  • selection and defaultSelection are the preferred SwiftUI-style value APIs
  • value and defaultValue remain available as React-friendly aliases
  • onChange forwards the native input event
  • onSelectionChange and onValueChange receive the latest string value
  • Supported modes are date, time, and dateAndTime
  • displayedComponents={['date', 'hourAndMinute']} maps to dateAndTime
  • Use min and max for native bounds in the same string format as value
  • minuteInterval maps to the native step attribute for time and dateAndTime modes
  • disabled behaves like a native input prop

Best Practices

  1. Mode selection: Choose date, time, or dateAndTime based on the required granularity
  2. String values: Keep the value in the browser's native input format for the selected mode
  3. Bounds: Use min and max to constrain user input
  4. Labels: Provide an accessible label or visible label
  5. Localization: Let the browser handle localized rendering of the native control

On this page