Relative Date Input

Stops a date typed the way people say it ("next Fri", "the 10th") from landing on the wrong day by asking when the phrase has two readings.

StopsNext Friday lands on the wrong day

Installation

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

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

Usage

relative-date-input-usage.tsx
import { RelativeDateInput } from "@/components/ui/relative-date-input"

<RelativeDateInput label="Invoice due" today={TODAY} expect="future" defaultValue="next Friday" onDateChange={setDue} />

What it catches

  • Phrases with two honest readings (next/this weekday, next weekend early in the week)
  • Day-of-month that has already passed ("the 10th")
  • Read-back of the resolved date with its relative distance
  • One-tap rewrite of the field to an unambiguous date

Props

RelativeDateInput props
PropTypeDefault
label

Visible label.

string"Date"
value

Controlled text.

string—
defaultValue

Initial text when uncontrolled.

string""
onValueChange

Called with the field's text.

(value: string) => void—
onDateChange

Called with `YYYY-MM-DD`, or null while the text is unreadable or still ambiguous.

(date: string | null) => void—
today

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

string—
weekStartsOn

First day of the week: 1 = Monday, 0 = Sunday. Decides what "this week" covers.

Day1
expect

Only future (bookings, deadlines) or only past (expenses) dates make sense here.

"future" | "past"—
locale

BCP 47 locale for the read-back.

string"en-GB"
messages

Override any text (see `RELATIVE_DATE_MESSAGES`).

Partial<RelativeDateMessages>—

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

Accessibility

  • Visible <label> on the input; aria-invalid and status via aria-describedby
  • Two readings form a roving-tabindex radiogroup operated with arrow keys
  • Read-back renders in a polite live region
  • Animations respect reduced motion (useReducedMotion)
  • After the rewrite, focus returns to the input

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

Limitations

  • English phrases only; other languages are not parsed
  • Uses the today you pass (or the device clock) and its time zone
  • Covers common everyday phrases, not every natural-language form

What it stops

Next Friday lands on the wrong day

Also known as

natural language date · relative date · next friday · due date · chrono · date-fns · reminder · task due

Field type

Dependencies

Pairs well with