Skip to main content

DatePicker

BasicInputs<co-date-picker>

DatePicker takes a date as MM/DD/YYYY by typing or from a month grid.

import { DatePicker } from 'health-components';

Examples​

Showcase​

Storybook

Calendar Open​

Storybook

Invalid Date​

Storybook

Read Only​

Storybook

Usage​

<DatePicker label="Date of Birth" required disableFuture defaultValue="03/14/1988" onChange={setDob} />

When to use​

  • Date of birth, date of service, coverage start and end, follow-up date.

When not to use​

  • Picking an appointment time: TimeSlotPicker.

Variants and states​

VariantWhat it is
closedTyped entry with mask.
openMonth grid, today ringed, selected filled.
limitsdisablePast, disableFuture (DOB), disableWeekends (scheduling).
errorBad or impossible date: "Enter a real date as MM/DD/YYYY."
readOnlyLock state.

Accessibility​

  • Typing always works; the grid is optional.
  • Grid days are buttons with aria-selected and aria-current="date" for today; month changes are announced.
  • The check on typed dates proves the date exists on the calendar. It does not prove it is plausible (a DOB of today): add that rule where it matters.

Do and don't​

  • Do: DOB with disableFuture.
  • Don't: A three-dropdown date (month, day, year).

Props​

PropTypeDefaultDescription
label *string—Visible label; required
valuestringundefined (uncontrolled)Controlled value, MM/DD/YYYY
defaultValuestring""Initial value (uncontrolled), MM/DD/YYYY
onChange(value: string) => voidnoneCalled with the MM/DD/YYYY text on typing and on picking a day
todaystringthe current dateToday's date, MM/DD/YYYY (marks the grid, limits past/future)
openbooleanundefined (uncontrolled)Controlled open state of the calendar
defaultOpenbooleanfalseCalendar open on first render (uncontrolled)
onOpenChange(open: boolean) => void—Called when the calendar opens or closes
disablePastbooleanfalseDays before today cannot be picked
disableFuturebooleanfalseDays after today cannot be picked (date of birth)
disableWeekendsbooleanfalseSaturdays and Sundays cannot be picked
errorstringnoneError message (as TextField); an impossible typed date shows "Enter a real date as MM/DD/YYYY."
helperstring'MM/DD/YYYY'Muted hint under the field
requiredbooleanfalseRed asterisk plus aria-required
readOnlybooleanfalseRead-only lock state; the calendar button is disabled
lockMessagestring'Your role can view but not edit'Lock line text when readOnly
styleCSSProperties—Inline style of the root

Also accepts native attributes, including defaultChecked, autoFocus, onInput, type, disabled, name, max, step, placeholder, accept, autoComplete, checked, maxLength, min, multiple, plus className and event handlers on the root element.

Angular, Vue and HTML​

Register the elements once (Angular guide), then use <co-date-picker>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.

Angular template
<co-date-picker label="…" value="…" [style]="style" (co-change)="onChange($event.detail)"></co-date-picker>
KindNameDescription
attributelabelVisible label; required
attributevalueControlled value, MM/DD/YYYY; default undefined (uncontrolled)
attributedefault-value / defaultValueInitial value (uncontrolled), MM/DD/YYYY; default ""
attributetodayToday's date, MM/DD/YYYY (marks the grid, limits past/future); default the current date
attributeopenControlled open state of the calendar; default undefined (uncontrolled)
attributedefault-open / defaultOpenCalendar open on first render (uncontrolled); default false
attributedisable-past / disablePastDays before today cannot be picked; default false
attributedisable-future / disableFutureDays after today cannot be picked (date of birth); default false
attributedisable-weekends / disableWeekendsSaturdays and Sundays cannot be picked; default false
attributeerrorError message (as TextField); an impossible typed date shows "Enter a real date as MM/DD/YYYY."; default none
attributehelperMuted hint under the field; default 'MM/DD/YYYY'
attributerequiredRed asterisk plus aria-required; default false
attributeread-only / readOnlyRead-only lock state; the calendar button is disabled; default false
attributelock-message / lockMessageLock line text when readOnly; default 'Your role can view but not edit'
property / JSON attributestyleInline style of the root
attributedefault-checked / defaultChecked
attributeauto-focus / autoFocus
property / JSON attributetype
attributedisabled
attributename
property / JSON attributemax
property / JSON attributestep
attributeplaceholder
attributeaccept
property / JSON attributeauto-complete / autoComplete
attributechecked
attributemax-length / maxLength
property / JSON attributemin
attributemultiple
eventco-changeCalled with the MM/DD/YYYY text on typing and on picking a day; default none (React: onChange)
eventco-open-changeCalled when the calendar opens or closes (React: onOpenChange)
eventco-input (React: onInput)