Skip to content

Description

The DatePicker component should be used whenever there is to enter a single date or a date range/period with a start and end date.

Date Object

The DatePicker operates with a default JavaScript Date instance as well as string (ISO 8601) like start_date="2019-05-05" (yyyy-MM-dd).

For more DatePicker examples, have a look at this CodeSandbox.

Demos

English (US) is not included in Eufemia by default. You can include it like:

import enUS from '@dnb/eufemia/shared/locales/en-US'
<EufemiaProvider locale={enUS} ...>
App
</EufemiaProvider>

Range DatePicker

Default DatePicker

DatePicker:

Code Editor
<DatePicker
  label="DatePicker:"
  date="2019-05-05"
  return_format="dd-MM-yyyy"
  on_change={({ date }) => {
    console.log('on_change', date)
  }}
  on_show={({ date }) => {
    console.log('on_show', date)
  }}
/>

Default DatePicker with Input

Hidden Nav:

Show month only

With info message

With suffix

Linked DatePickers

DatePicker:

Code Editor
<DatePicker label="DatePicker:" range link show_input />

DatePicker with error status (no input)

Please select a valid date
DatePicker:

Code Editor
<DatePicker
  label="DatePicker:"
  date="2019-05-05"
  hide_navigation={true}
  status="Please select a valid date"
/>

DatePicker with error

Status message with HTML inside
DatePicker:

Code Editor
<DatePicker
  label="DatePicker:"
  date="2019-05-05"
  show_input={true}
  show_submit_button={true}
  stretch={true}
  status={
    <span>
      Status message with <b>HTML</b> inside
    </span>
  }
/>

DatePicker with error status

DatePicker:

Code Editor
<DatePicker
  label="DatePicker:"
  date={new Date()}
  hide_navigation={true}
  status="error"
/>

Opened DatePicker

Also used for screenshot tests.

Code Editor
<DatePicker
  opened={true}
  prevent_close={true}
  disable_autofocus={true}
  range={true}
  start_date="2019-05-05"
  end_date="2019-06-05"
/>