HextaUI

Time input (UI SDK): Min and max

A time before min or after max marks the field invalid, and its form won’t submit.

Open 09:00 to 17:30.

"use client"

import * as React from "react"

import { Label } from "@/components/ui/label"
import { TimeInput } from "@/components/ui/ui-sdk-time-input"

const opens = "09:00"
const closes = "17:30"

function UiSdkTimeInputMinMax() {
  const [time, setTime] = React.useState<string | null>("16:00")
  const outside = time !== null && (time < opens || time > closes)

  return (
    <div className="flex w-full max-w-40 flex-col gap-2">
      <Label id="pickup-time">Pickup</Label>
      <TimeInput
        aria-labelledby="pickup-time"
        aria-describedby="pickup-time-message"
        defaultValue="16:00"
        min={opens}
        max={closes}
        hourCycle={24}
        onValueChange={(value) => setTime(value)}
      />
      <p
        id="pickup-time-message"
        className={
          outside
            ? "m-0 text-xs text-destructive"
            : "m-0 text-xs text-muted-foreground"
        }
      >
        {outside ? "We’re closed then." : "Open 09:00 to 17:30."}
      </p>
    </div>
  )
}

export { UiSdkTimeInputMinMax }

This adds the example as components/examples/ui-sdk-time-input/min-max.tsx, together with the Time input component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/ui-sdk-time-input-min-max.json

To add only the component, follow the Time input installation.

Props in this example

The Time input props this example sets, from the API reference.

PropTypeDefault
defaultValue
string | null–
onValueChangeRuns once every part holds something, and with null when one is emptied.
(value: string | null, details) => void–
hourCycleDefaults to the locale’s clock.
12 | 24–
min
string–
max
string–

Every prop is in the Time input API reference.

See them all, with keyboard support and accessibility notes, on the Time input page.