HextaUI

Date picker: In a form

With name, a single date is submitted as 2026-10-14 and a range as 2026-10-20/2026-10-24. Empty pickers submit an empty string.

Not submitted
"use client"

import * as React from "react"

import { Button } from "@/components/ui/button"
import { DatePicker, DateRangePicker } from "@/components/ui/date-picker"

export function DatePickerForm() {
  const [submitted, setSubmitted] = React.useState<string>()

  return (
    <form
      className="flex flex-col items-start gap-3"
      onSubmit={(event) => {
        event.preventDefault()
        const data = new FormData(event.currentTarget)
        setSubmitted(JSON.stringify(Object.fromEntries(data)))
      }}
    >
      <DatePicker name="due" defaultValue={new Date(2026, 9, 14)} />
      <DateRangePicker
        name="stay"
        defaultValue={{
          from: new Date(2026, 9, 20),
          to: new Date(2026, 9, 24),
        }}
      />
      <Button type="submit">Submit</Button>
      <output className="text-sm break-all text-muted-foreground">
        {submitted ?? "Not submitted"}
      </output>
    </form>
  )
}

This adds the example as components/examples/date-picker/form.tsx, together with the Date picker component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/date-picker-form.json

To add only the component, follow the Date picker installation.

Props in this example

The Date picker props this example sets, from the API reference.

PropTypeDefault
defaultValue
Date | nullnull
nameRenders a hidden input so the value is submitted with its form.
string–
PropTypeDefault
defaultValue
{ from: Date; to?: Date } | nullnull
nameRenders a hidden input so the value is submitted with its form.
string–

Every prop is in the Date picker API reference.

See them all, with keyboard support and accessibility notes, on the Date picker page.