Date Sanity Input

Reads a date back with its weekday and catches year typos, dates on the wrong side of today and weekends, so bookings aren't made for the wrong day.

StopsBooked on the wrong date

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/date-sanity-input.json

The files land in your project. They're yours to edit.

Usage

date-sanity-input-usage.tsx
import { DateSanityInput } from "@/components/ui/date-sanity-input"

<DateSanityInput label="Check-in" expect="future" today={TODAY} defaultValue="2062-11-08" />

What it catches

  • Year typos (2062 for 2026)
  • A past date where a future one is expected, or the reverse
  • Dates more than maxYearsAway from today
  • Weekends, when warnWeekends is on
  • The weekday, read back so the user can spot a wrong day

Props

DateSanityInput props
PropTypeDefault
label

Visible label.

string"Date"
hint

Helper text shown before a date is picked.

string—
value

Controlled value as `YYYY-MM-DD`, or `""`.

string—
defaultValue

Initial value when uncontrolled.

string""
onValueChange

Called with the `YYYY-MM-DD` value (or `""`).

(value: string) => void—
expect

Warn when the date is on the wrong side of today: `future` for bookings, `past` for a date of birth.

"future" | "past"—
maxYearsAway

Dates more than this many years from today are treated as a likely year typo.

number10
warnWeekends

Warn when the date falls on a Saturday or Sunday.

booleanfalse
today

"Today" as `YYYY-MM-DD`. Defaults to the user's local date once mounted.

string—
locale

Locale for the weekday and dates in messages.

string"en-IN"
messages

Override any text. Templates: `{weekday}` and `{relative}` in `readback`, `{date}` in the fix labels.

Partial<DateSanityMessages>—

* required. Also accepts the native props of <input> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Visible <label>; aria-describedby to an aria-live="polite" status
  • Fix returns focus to the input
  • Motion respects prefers-reduced-motion

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

  • Doesn't know holidays or business-specific closed days
  • "Today" is the visitor's clock unless you pass `today`

What it stops

Booked on the wrong date

Also known as

date picker · date input · booking date · dob · date of birth · appointment · travel date · calendar

Field type

Dependencies

Pairs well with