Skip to content
SENVENLI UI

Date field

A typed date (or date and time) in the locale's order, with min/max and month-day mode.
A typed date
import { DateField } from "@senvenli/react/date";

Examples

With a range

`minValue` and `maxValue` bound what can be typed; a date outside says so.

Month and year

A card's expiry: no day, and the value is the month's first day.

Day and month

A yearly date with no year, such as a birthday reminder.

Guidelines

When to use it

  • Typing a known date: a birthday, an expiry date.

Use something else when

Accessibility

Keyboard

KeysWhat happens
Arrow up / downChanges the focused part.

Built in

  • Required fields show "Fill in this field."; a partly typed date says what is missing.

You provide

  • A visible label.

API reference

DateField

labelRequired
React.ReactNode

Always given; the label sits above the field and names its segments.

description
React.ReactNode
errorMessage
React.ReactNode

What happened and what to do; shown when the field is invalid.

isRequired
boolean
requiredValidation
RequiredValidation

Who says an empty required field is missing: field (default) or app. With app a DS Form's onSubmit runs with the field empty, and the app's own error must clear on change. See {@link RequiredValidation} for the whole contract.

isOptional
boolean

Shows "(optional)" when most of the form is required.

isDisabled
boolean
isReadOnly
boolean
isInvalid
boolean

Marks the field invalid from outside (a server error); errorMessage says why.

id
string

The id of the field's first typed segment (day, or the locale's first part), the element that takes focus : document.getElementById(id).focus() puts the user in the field, as a focus-on-error does. The field's group gets an id of its own. Left out, the DOM is as before.

name
string

The form field name; the value is submitted as an ISO string.

autoFocus
boolean
onBlur
(event: FocusEvent<Element, Element>) => void
value
CalendarDate

A calendar date, no time zone. With hideYear its year is 2000 (a leap year, so 29 February exists; see hideYear); with granularity="month" it is the month's first day.

While the user leaves a date typed in part or impossible ("31.aa.2026", "31.11.2026"), the field reports onChange(null) and keeps the typed parts on screen, so setting null changes nothing: the value already is null. To clear the field (an app's own "Temizle" or form reset), give it a new key along with the value: React remounts it empty, or at the value given.

defaultValue
CalendarDate
onChange
(value: CalendarDate | null) => void
granularity
"day" | "month"Default "day"

day types day, month and year; month types month and year (a card's expiry) and the day is 1.

hideYear
boolean

Day and month only: a yearly date (a campaign day, a birthday reminder). The value is that day in the Gregorian year 2000, a leap year, so 29 February exists, whatever calendar the locale writes dates in: - A calendar with the Gregorian months (the Buddhist one of th-TH, ROC, Japanese): the day and month are typed as the locale writes them, and the hidden year is 2000 as that calendar counts it (2543, Minguo 89, Heisei 12), its era hidden with it. - A calendar with months of its own (Hebrew, Islamic, Persian, Indian, Ethiopic, Coptic, Chinese): one of its days falls on another Gregorian day every year, so no month–day of it is a yearly date the value can hold. The field types the Gregorian day and month instead, in the locale's language and digits.

Give value and defaultValue in 2000 (new CalendarDate(2000, month, day)). The field never changes the year it is given: a value in another year keeps it, an edit reports in it, and the day is judged in it, so 29 February typed over a 2023 value says "February has 28 days." and reports null.

minValue
CalendarDate
maxValue
CalendarDate
validate
(value: CalendarDate | null) => string | true | string[] | null | undefined

Your own check; return the message to show, or nothing when the date is fine.