Skip to main content

DateTimePicker

DateTimePicker combines a Fluent UI calendar with optional time selection. Popup edits (date, time, AM/PM, Now, Clear) build an internal draft; the parent is notified once via onChange when the user presses Done — so you're not flooded with intermediate updates. When showTime is off, selecting a date commits immediately.

When to use

  • Capture a date, or a date + time, with a single field.
  • Forms needing min/max bounds, optional text entry, and localized calendars.

Import

import { DateTimePicker } from '@spartanfx/react';

Basic usage

onChange is the only required prop. It fires with a local-timezone Date when the value is committed.

function Example() {
const [when, setWhen] = React.useState<Date | undefined>();
return (
<DateTimePicker
label="Due date"
value={when}
onChange={setWhen}
showTime
/>
);
}

Date only

Omit showTime to select a date that commits on click (no Done step):

<DateTimePicker label="Start date" value={date} onChange={setDate} />

Bounds, text input, and clearing

<DateTimePicker
label="Appointment"
value={value}
onChange={setValue}
showTime
minDate={new Date()}
maxDate={maxBookingDate}
minuteStep={15}
allowTextInput
allowClear
required
errorMessage={error}
/>

Key props

PropTypeDefaultNotes
onChange (required)(date) => voidFires when the value is committed.
valueDateControlled current value.
showTimebooleanInclude time selection (adds the Done step).
minDate / maxDateDateSelectable bounds (time ignored).
minuteStepnumber1Minutes increment.
allowTextInputbooleanfalseAllow typing into the field.
allowClearbooleantrueShow a clear button.
required / errorMessageboolean / stringForm validation display.
label / placeholderstringField label and placeholder.

See the full generated reference: DateTimePicker API ↗.

See also