DatePicker

đź“”
This component is in an experimental state; you can use it in your app. However, we may modify it, and it may even have breaking changes in the future.

A datepicker component enables the selection of a date or a range of dates in a specified format from an interactive display.

Properties

autoFocus (default: false)

If this property is set to true, the component gets the focus automatically when displayed.

dateFormat (default: "MM/dd/yyyy")

The format of the date displayed in the input field

Available values: MM/dd/yyyy (default), MM-dd-yyyy, yyyy/MM/dd, yyyy-MM-dd, dd/MM/yyyy, dd-MM-yyyy, yyyyMMdd, MMddyyyy

Formats handle years (y), months (m or M), days of the month (d). Providing multiple placeholder letters changes the display of the date.

The table below shows the available date formats:

FormatExample
MM/dd/yyyy05/25/2024
MM-dd-yyyy05-25-2024
yyyy/MM/dd2024/05/25
yyyy-MM-dd2024-05-25
dd/MM/yyyy25/05/2024
dd-MM-yyyy25-05-2024
yyyyMMdd20240525
MMddyyyy05252024
<App>
  <DatePicker dateFormat="dd-MM-yyyy" initialValue="05/25/2024" />
</App>

disabledDates

An array of dates that are disabled

<App>
  <DatePicker disabledDates="{['05/26/2024', '05/27/2024']}" initialValue="05/25/2024" />
</App>  

enabled (default: true)

This boolean property value indicates whether the component responds to user events (true) or not (false).

<App>
  <DatePicker enabled="false" />
</App>  

endIcon

This property sets an icon to appear on the end (right side when the left-to-right direction is set) of the input.

endText

This property sets a text to appear on the end (right side when the left-to-right direction is set) of the input.

fromDate

The start date of the range of selectable dates

<App>
  <DatePicker fromDate="05/24/2024" />
</App>

initialValue

This property sets the component's initial value.

<App>
  <DatePicker initialValue="05/25/2024" />
</App>  

inline (default: false)

Whether to display the datepicker inline

mode (default: "single")

The mode of the datepicker (single or range)

Available values: single (default), range

<App>
  <DatePicker mode="single" />
  <DatePicker mode="range" />
</App>

placeholder

A placeholder text that is visible in the input field when its empty.

<App>
  <DatePicker placeholder="This is a placeholder" />
</App>  

readOnly (default: false)

Set this property to true to disallow changing the component value.

showWeekNumber (default: false)

Whether to show the week number in the calendar

<App>
  <DatePicker showWeekNumber="true" />
</App>

startIcon

This property sets an icon to appear at the start (left side when the left-to-right direction is set) of the input.

startText

This property sets a text to appear at the start (left side when the left-to-right direction is set) of the input.

toDate

The end date of the range of selectable dates

<App>
  <DatePicker toDate="05/26/2024" />
</App>

validationStatus (default: "none")

This property allows you to set the validation status of the input component.

Available values:

ValueDescription
validVisual indicator for an input that is accepted
warningVisual indicator for an input that produced a warning
errorVisual indicator for an input that produced an error
ValueDescription
validVisual indicator for an input that is accepted
warningVisual indicator for an input that produced a warning
errorVisual indicator for an input that produced an error
<App>
  <DatePicker />
  <DatePicker validationStatus="valid" />
  <DatePicker validationStatus="warning" />
  <DatePicker validationStatus="error" />
</App>

weekStartsOn (default: 0)

The first day of the week. 0 is Sunday, 1 is Monday, etc.

Available values:

ValueDescription
0Sunday (default)
1Monday
2Tuesday
3Wednesday
4Thursday
5Friday
6Saturday
DayNumber
Sunday0
Monday1
Tuesday2
Wednesday3
Thursday4
Friday5
Saturday6
<App>
  <DatePicker weekStartsOn="1" />
</App>

Events

didChange

This event is triggered when value of DatePicker has changed.

Write in the input field and see how the Text underneath it is updated in parallel.

<App var.field="">
  <DatePicker initialValue="{field}" onDidChange="(val) => field = val" />
  <Text value="{field}" />
</App>

gotFocus

This event is triggered when the DatePicker has received the focus.

Clicking on the DatePicker in the example demo changes the label text. Note how clicking elsewhere resets the text to the original.

<App var.isFocused="false">
  <Text value="{isFocused === true ? 'DatePicker focused' : 'DatePicker lost focus'}" />
  <DatePicker
    onGotFocus="isFocused = true"
    onLostFocus="isFocused = false"
  />
</App>

lostFocus

This event is triggered when the DatePicker has lost the focus.

Exposed Methods

focus

This method sets the focus on the DatePicker.

setValue

You can use this method to set the component's current value programmatically (true: checked, false: unchecked).

<App>
  <DatePicker
    id="picker"
    readOnly="true"
  />
  <HStack">
    <Button
      label="Add Text"
      onClick="picker.setValue('05/25/2024')" />
    <Button
      label="Remove Text"
      onClick="picker.setValue('')" />
  </HStack>
</App>

value

You can query the component's value. If no value is set, it will retrieve undefined.

Styling

The DatePicker component provides these theme variables to customize its appearance:

  • borderRadius-DatePicker
  • textColor-DatePicker
  • backgroundColor-DatePicker--disabled
  • borderWidth-DatePicker
  • borderStyle-DatePicker
  • borderColor-DatePicker--disabled
  • backgroundColor-DatePicker--disabled
  • textColor-DatePicker--disabled
  • textColor-value-DatePicker
  • borderColor-DatePicker-default
  • borderColor-DatePicker-error
  • borderColor-DatePicker-warning
  • borderColor-DatePicker-success
  • color-placeholder-DatePicker
  • backgroundColor-menu-DatePicker
  • boxShadow-menu-DatePicker
  • borderRadius-menu-DatePicker
  • backgroundColor-item-DatePicker--hover
  • backgroundColor-item-DatePicker--active
{
  "borderRadius-DatePicker": "30px",
  "borderWidth-DatePicker": "4px",
  "borderRadius-menu-DatePicker": "30px",
  "textColor-DatePicker": "black",
  "backgroundColor-menu-DatePicker": "#f5f5dc"
}

To style all input controls not just this component, use Input instead of the DatePicker segment:

textColor-Input: "#0033FF"

Input affects the following controls:

See custom themes for styling details.

Theme Variables

VariableDefault Value (Light)Default Value (Dark)
backgroundColor-DatePicker--disabled

none

none

backgroundColor-DatePicker-default

none

none

backgroundColor-DatePicker-default--hover

none

none

backgroundColor-DatePicker-error

none

none

backgroundColor-DatePicker-error--hover

none

none

backgroundColor-DatePicker-success

none

none

backgroundColor-DatePicker-success--hover

none

none

backgroundColor-DatePicker-warning

none

none

backgroundColor-DatePicker-warning--hover

none

none

backgroundColor-item-DatePicker--active$color-surface-200$color-surface-200
backgroundColor-item-DatePicker--active$color-surface-200$color-surface-200
backgroundColor-item-DatePicker--hover$color-surface-100$color-surface-100
backgroundColor-item-DatePicker--hover$color-surface-100$color-surface-100
backgroundColor-menu-DatePicker$color-surface-50$color-surface-50
backgroundColor-menu-DatePicker$color-surface-50$color-surface-50
borderColor-DatePicker--disabled

none

none

borderColor-DatePicker-default

none

none

borderColor-DatePicker-default--hover

none

none

borderColor-DatePicker-error

none

none

borderColor-DatePicker-error--hover

none

none

borderColor-DatePicker-success

none

none

borderColor-DatePicker-success--hover

none

none

borderColor-DatePicker-warning

none

none

borderColor-DatePicker-warning--hover

none

none

borderRadius-DatePicker-default

none

none

borderRadius-DatePicker-error

none

none

borderRadius-DatePicker-success

none

none

borderRadius-DatePicker-warning

none

none

borderRadius-menu-DatePicker$borderRadius$borderRadius
borderRadius-menu-DatePicker$borderRadius$borderRadius
borderStyle-DatePicker-default

none

none

borderStyle-DatePicker-error

none

none

borderStyle-DatePicker-success

none

none

borderStyle-DatePicker-warning

none

none

borderWidth-DatePicker-default

none

none

borderWidth-DatePicker-error

none

none

borderWidth-DatePicker-success

none

none

borderWidth-DatePicker-warning

none

none

boxShadow-DatePicker-default

none

none

boxShadow-DatePicker-default--hover

none

none

boxShadow-DatePicker-error

none

none

boxShadow-DatePicker-error--hover

none

none

boxShadow-DatePicker-success

none

none

boxShadow-DatePicker-success--hover

none

none

boxShadow-DatePicker-warning

none

none

boxShadow-DatePicker-warning--hover

none

none

boxShadow-menu-DatePicker$boxShadow-md$boxShadow-md
boxShadow-menu-DatePicker$boxShadow-md$boxShadow-md
fontSize-DatePicker

none

none

minHeight-DatePicker

none

none

outlineColor-DatePicker-default--focus

none

none

outlineColor-DatePicker-error--focus

none

none

outlineColor-DatePicker-success--focus

none

none

outlineColor-DatePicker-warning--focus

none

none

outlineOffset-DatePicker-default--focus

none

none

outlineOffset-DatePicker-error--focus

none

none

outlineOffset-DatePicker-success--focus

none

none

outlineOffset-DatePicker-warning--focus

none

none

outlineStyle-DatePicker-default--focus

none

none

outlineStyle-DatePicker-error--focus

none

none

outlineStyle-DatePicker-success--focus

none

none

outlineStyle-DatePicker-warning--focus

none

none

outlineWidth-DatePicker-default--focus

none

none

outlineWidth-DatePicker-error--focus

none

none

outlineWidth-DatePicker-success--focus

none

none

outlineWidth-DatePicker-warning--focus

none

none

padding-DatePicker-default

none

none

padding-DatePicker-error

none

none

padding-DatePicker-success

none

none

padding-DatePicker-warning

none

none

textColor-adornment-DatePicker-default

none

none

textColor-adornment-DatePicker-error

none

none

textColor-adornment-DatePicker-success

none

none

textColor-adornment-DatePicker-warning

none

none

textColor-DatePicker--disabled

none

none

textColor-DatePicker-default

none

none

textColor-DatePicker-default--hover

none

none

textColor-DatePicker-error

none

none

textColor-DatePicker-error--hover

none

none

textColor-DatePicker-success

none

none

textColor-DatePicker-success--hover

none

none

textColor-DatePicker-warning

none

none

textColor-DatePicker-warning--hover

none

none

textColor-placeholder-DatePicker-default

none

none

textColor-placeholder-DatePicker-error

none

none

textColor-placeholder-DatePicker-success

none

none

textColor-placeholder-DatePicker-warning

none

none

textColor-value-DatePicker$textColor-primary$textColor-primary
textColor-value-DatePicker$textColor-primary$textColor-primary