Date of Birth Input
DOBInput is three numeric fields instead of a calendar, which is faster for dates decades back. Focus moves on as soon as a field can't take another digit. Type 31 02 1990: the result stays undefined because the date isn't real.
@dentil/dob-inputOn this page
Result:
undefinedcomponents/demos/dob-input-overview.tsx
'use client';
import { useState } from 'react';
import { DOBInput, type DOB } from '@/components/dentil/dob-input/dob-input';
export function DobInputOverviewDemo() {
const [dob, setDob] = useState<DOB>();
return (
<div className="flex flex-col items-start gap-4">
<DOBInput value={dob} onChange={setDob} />
<span className="text-muted-foreground text-sm">
Result: <code className="text-foreground">{dob ? JSON.stringify(dob) : 'undefined'}</code>
</span>
</div>
);
}Installation
pnpm dlx shadcn@latest add @dentil/dob-inputnpx shadcn@latest add @dentil/dob-inputyarn dlx shadcn@latest add @dentil/dob-inputbunx --bun shadcn@latest add @dentil/dob-inputFiles land in components/dentil/dob-input/. Uses the stock shadcn input-group and react-number-format.
API reference
DOBInput
| Prop | Type | Default | Description |
|---|---|---|---|
| value | { day; month; year } | null | undefined | — | Day and month are 1-based. |
| onChange | (value: DOB | undefined) => void | — | Called on every keystroke: with the date once the three fields form a real date with a four-digit year, and undefined otherwise. 31/02 never reaches you. |
| disabled | boolean | false | Disables the three fields. |
| …props | ComponentProps<'input'> | — | Other props (id, aria-invalid, aria-describedby, onBlur…) are passed to the day input. aria-invalid also reaches month and year. |