Datetime

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

Props

Datetime 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

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

<Datetime defaultValue={new Date().toISOString()} />
<Datetime defaultValue={new Date()} />
<Datetime defaultValue={(new Date()).getTime()} />
Copy

Events

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

<Datetime 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.

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

Custom Styles

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