DatePicker

DatePicker allows for the selection of dates, supporting single, multiple and range of dates.

Internal Component

This component is intended solely for use within GitHub and is not available for external use.

Props

DatePicker

NameDefaultDescription
anchor
"button"
AnchorVariant | RenderAnchor | React.RefObject<HTMLElement>

The anchor is the inline element that the user will interact with to trigger the datepicker.

Built-in anchors include:

  • 'button': A button that users can click to open the picker.
  • 'input': A text input box that users can type dates into if they prefer.
  • 'icon-only': A button that is styled as a calendar icon for integration into other components.

To use a custom anchor, either provide a render function here or provide a ref to an externally rendered anchor. If a render function is provided, the current selection string will be provided as the children prop.

anchorClassName
string

Optional style overrides for the anchor. Ignored if a custom anchor is used.

disabled
false
boolean

Control whether the datepicker is disabled or not.

confirmation
false
boolean

Control whether the user needs to press a button to apply their changes. If false, the datepicker will apply changes and close as soon as a selection is made.

confirmUnsavedClose
false
boolean

Control whether the user should confirm their changes if they exit the picker without saving. If true, the picker will be put into confirmation mode, regardless of the value of the confirmation prop.

compressedHeader
false
boolean

Show a smaller header with month/year dropdowns.

dateFormat
short
string

Control how the selection will be displayed in the anchor.

disableWeekends
false
boolean

If true, users will not be able to select weekends (Saturday or Sunday).

iconPlacement
start
IconPlacement

Control where the calendar icon will display on the anchor.

maxDate
Date

The maximum date the user can select. This is inclusive - the user can select the maxDate but not any date after.

minDate
Date

The minimum date the user can select. This is inclusive - the user can select the minDate but not any date before.

showInputs
true
boolean

Control whether inputs are shown inside the picker. Inputs are not shown when confirmation mode is disabled or when variant is 'multi'.

showTodayButton
true
boolean

Control whether to show a 'today' button in the picker. This button will cause today's date to appear and be focused. If today's date is outside the allowed range (defined by minDate and maxDate, the button will not be displayed.

showClearButton
false
boolean

Control whether to show a 'clear' button in the picker. This button will set the date to null.

view
1-month
"1-month" | "2-month"

Control the size of the datepicker. Will always be '1-month' on screens too small to display 2 months side-by-side.

weekStartsOn
Sunday
DayOfWeek

Determine the day of the week that is shown in the first column when displaying a month.

placeholder
Choose date...
string

Placeholder string when there is no selection.

fieldName
string

The name of the field that this datepicker is associated with. This is used in the aria-label, otherwise defaults to "Date"

onChange
((selection: Date) => void) | ((selection: Date[]) => void) | ((selection: RangeSelection) => void)

Called when the selection changes. For confirmation datepicker, onChange will only be called one time, when the user clicks to confirm.

open
boolean

Determines whether the overlay portion of the component should be shown or not. If not defined, the date picker will manage its own internal closed/open state.

onClose
(gesture: CloseGesture | SubmitGesture) => void

A callback which is called whenever the overlay is currently open and a "close" or "submit" gesture is detected.

onOpen
(gesture: OpenGesture) => void

A callback which is called whenever the overlay is currently closed and an "open gesture" is detected.

value Required
Date | Date[] | RangeSelection

Current value of the picker.

anchoredOverlayProps
DatePickerAnchoredOverlayProps

Props to be spread on the internal AnchoredOverlay component. DatePicker props will take precedence in the event of a conflict.

configuration
Partial<BaseDatePickerConfig> | Partial<MultiDatePickerConfig> | Partial<RangeDatePickerConfig>

Configuration object, if you'd like to reuse a single configuration object among multiple pickers. These can also be supplied as top-level props. If any top-level props conflict with the configuration object props, the top-level props will apply instead.

variant Required