Date

import Date from 'frui/fields/Date';
Copy

Props

Dates accepts all props of a standard HTML Input element. See Moz for standard input attributes.

NameTypeRequiredNotes
classNamestringNoStandard HTML class names
defaultValuestring|number|DateNoDefault value (Uncontrolled)
errorstring|booleanNoAny error message
namestringNoUsed for react server components.
onChangeFunctionNoEvent handler when value has changed
onUpdateFunctionNoUpdate event handler
passRefLegacyRefNoPasses ref to html input
styleCSS ObjectNoStandard CSS object
valuestring|number|DateNoDefault value (Controlled)

Basics

Date fields use the default `<input type="date" />` element, but normalizes values to ISO strings using toISOString(). onUpdate is like onChange except the value is passed instead of the change event.

<DateField defaultValue={'2024-02-03 12:00:00'} />
<DateField defaultValue={new Date()} />
<DateField defaultValue={(new Date()).getTime()} />
Copy
When using the native Date object, change import to import DateField from 'frui/fields/Date' or whatever name you like.

Events

onUpdate is like onChange except the value is passed instead of the change event.

<Date onUpdate={value => alert(value)} />
Copy

On Change

The onChange event is triggered when the value has changed. The following arguments are passed to the event handler:

NameTypeSample
eventEvent Objectsee: Change Event

On Update

The onUpdate event is triggered when the value has been updated. The following arguments are passed to the event handler:

NameTypeSample
valuestring`2024-12-01T00:00:00.000Z`

Errors

You can pass the error prop to highlight the input field red.

<Date error={string|true} value="Invalid Date." />
Copy

Custom Styles

You can add your own custom class to date or use the frui-field-time CSS class.