<State initial={undefined}>
{([date, setDate]) => (
<DatePicker value={date} onChange={(v) => setDate(v)} />
)}
</State>
States
Default Value
<State initial={new Date()}>
{([date, setDate]) => (
<Form>
<Form.DatePicker
label='Date Label'
description="Description goes here..."
value={date}
onChange={(v) => setDate(v)}
/>
</Form>
)}
</State>
Label Help
Labels can have a help icon with a tooltip to provide additional context to a label.
<State initial={undefined}>
{([date, setDate]) => (
<Form>
<Form.DatePicker
label='Date Label'
value={date}
labelProps={{
help: "This is help text",
direction: "r"
}}
onChange={(v) => setDate(v)} />
</Form>
)}
</State>
Required and Optional
A visual indicator can be applied on a Date Picker's label.
<Form>
<State initial={undefined}>
{([date, setDate]) => (
<Form.DatePicker
label="Date Label"
value={date}
labelProps={{
required: true
}}
onChange={(v) => setDate(v)}
/>
)}
</State>
<State initial={undefined}>
{([date, setDate]) => (
<Form.DatePicker
label="Date Label"
value={date}
labelProps={{
optional: true
}}
onChange={(v) => setDate(v)}
/>
)}
</State>
</Form>
With Placeholder
<State initial={undefined}>
{([date, setDate]) => (
<Form>
<Form.DatePicker
label='Date Label'
value={date}
placeholder="mm/dd/yy"
onChange={(v) => setDate(v)}
/>
</Form>
)}
</State>
Disabled
<State initial={new Date()}>
{([date, setDate]) => (
<Form>
<Form.DatePicker label='Date Label' value={date} onChange={(v) => setDate(v)} disabled />
</Form>
)}
</State>
Error
<State initial={new Date()}>
{([date, setDate]) => (
<Form>
<Form.DatePicker label='Date Label' value={date} onChange={(v) => setDate(v)} error />
</Form>
)}
</State>
<State initial={new Date()}>
{([date, setDate]) => (
<Form>
<Form.DatePicker
label='Meeting Date'
value={date}
onChange={(v) => setDate(v)}
error={date > new Date() ? false : "Date must be greater than today."}
/>
</Form>
)}
</State>
Accessibility
The user should be able to choose a date by typing into the input or by selecting a date from the calendar dropdown. The user should be able to use either method.
Keyboard Support
- When focus is on the input, press
space
to open and escape
to close the calendar.
- Use
tab
/ shift + tab
to change focus from the calendar and input.
- When focus is on the calendar, use the arrow keys to traverse through dates and
enter
to select a date.
Content Guidelines
Most of the content guidelines from Forms applies to the Date Picker.
A label is a short, meaningful description that clearly indicates what the user is expected to enter. Labels should be 1 to 3 words and written in title case. Labels should primarily be nouns. Avoid using labels as CTAs. A label is not inline help and shouldn’t be used to provide instruction.
Follow capitalization rules
Input labels should be written in title case.
Inline help should explain a feature or the outcome of the actions the user is about to take.
The description should adapt to the situation and context. The guidance could be focused on what is needed, or it could describe how to enter it.
Best Practices
Date pickers should:
- Use smart defaults
- Not be used to enter a date that is many years in the future or the past
Components
Patterns
- Form design pattern for how related controls are ordered.
Importing
import { DatePicker } from '@servicetitan/design-system';