DateRangePicker New Alpha Light DOM & Tailwind
Lets users choose a start and end date as a single range, from a list of presets or a range calendar.
Usage
Date Range Picker lets people choose a start and end date as a single range. They can pick a built-in preset (Today, Last 7 days, This month, …) or drag out a range across the calendar, which shows two months side by side on wider screens and a single month on narrow ones. Reach for it for reporting periods, filters and any "from–to" date input.
The date range picker renders its built-in label, hint and error on its own. Wrapped in a Field, the Field takes over with a Field Label, Field Description and Field Error, and the built-in versions step aside automatically.
import "@nordhealth/components/lib/DateRangePicker"
import "@nordhealth/components/lib/Field"
import "@nordhealth/components/lib/FieldLabel"
import "@nordhealth/components/lib/FieldDescription"
import "@nordhealth/components/lib/FieldError"
The committed value is an ISO-8601 interval string YYYY-MM-DD/YYYY-MM-DD. The convenience start-date / end-date properties and the valueAsDateRange getter/setter stay in sync with it.
Selecting in the popout builds a pending range. Apply commits it (firing a change event), Cancel reverts to the last committed value, and Clear empties the selection.
Standalone or inside a Field
Use the control on its own with its built-in label, hint and error, or wrap it in a Field — the Field then provides the labelling. Both render the same control:
Examples
Presets
A built-in list of presets is shown by default. Add hide-presets to suppress it and show only the calendar.
Error
Show validation with a Field Error and mark the Field invalid.
Required
Mark a field as required by setting required on the Field Label.
Two-field form submission
By default the picker submits the interval string under its name. Set both start-name and end-name to instead submit the start and end as two separate form fields.
Min and max
Constrain the selectable dates with min and max (both ISO YYYY-MM-DD). Dates outside the range are disallowed in the calendar, and a committed range that falls outside the bounds sets a validation error.
Inline
Set inline to render the presets, calendar and actions directly on the page, with no trigger button or popout. Useful when the picker lives in a form rather than behind a trigger.
Custom trigger
Provide your own trigger element with slot="trigger" and it replaces the built-in button while keeping all the popout behaviour. This is how you compose the picker into a Filter Bar — drop a filter chip in as the trigger. The picker wires aria-haspopup, aria-controls and aria-expanded onto whatever you provide.
Disabled
Add disabled to prevent interaction while still showing the committed value.
Invalid
Mark the Field invalid and pair it with a Field Error to convey a validation problem.
Sizes
The size attribute accepts s, m (default) and l.
RTL
Date Range Picker follows the document or container direction. Toggle the direction to see the layout mirror.
Accessibility
- Give the date range picker an accessible name with its built-in
label, or — inside a Field — a Field Label connected viafor. - Convey validation with a Field Error rather than colour alone — it is associated with the control and announced to assistive technology.
- Mark required fields by setting
requiredon the Field Label; it shows the indicator and marks the control required. - The trigger is a button that opens a dialog popout; it exposes
aria-haspopup,aria-expandedandaria-controlsso assistive tech announces its state. - The range calendar is fully keyboard navigable: move with the arrow keys, jump months with Page Up / Page Down, and pick the start and end with Enter or Space.
- The preset list, calendar and Apply / Cancel / Clear actions are all reachable and labelled, and every label is localizable.
API reference
DateRangePicker
Date Range Picker lets people choose a start and end date as a single range,
either from a built-in list of presets (Today, Last 7 days, This month, …) or
from a range calendar. It is a control only — compose it inside a
Field for a label, hint or error, like a native input.
The committed value is an ISO-8601 interval string YYYY-MM-DD/YYYY-MM-DD;
the convenience start-date / end-date props and the valueAsDateRange
getter/setter stay in sync with it. Selecting in the popout builds a *pending*
range; **Apply** commits it (firing change), **Cancel** reverts to the last
committed value, and **Clear** empties it.
<nord-date-range-picker></nord-date-range-picker>Props
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
value | value | The committed value as an ISO-8601 interval string YYYY-MM-DD/YYYY-MM-DD.
An empty string means no range is committed. | string | '' |
startDate | start-date | Convenience accessor for the committed start date, in ISO-8601 format. Kept
in sync with value and end-date. | string | '' |
endDate | end-date | Convenience accessor for the committed end date, in ISO-8601 format. Kept in
sync with value and start-date. | string | '' |
open | open | Controls whether the popout is open. | boolean | false |
min | min | Minimum date allowed to be picked, in ISO-8601 format: YYYY-MM-DD. | string | undefined | — |
max | max | Maximum date allowed to be picked, in ISO-8601 format: YYYY-MM-DD. | string | undefined | — |
today | today | The date that is considered today, in ISO-8601 format. Presets resolve relative to this; if unset, the user's current local date is used. | string | undefined | — |
firstDayOfWeek | first-day-of-week | Which day is considered the first day of the week. 0 for Sunday, 1 for
Monday, etc. Default is Monday. | DaysOfWeek | — |
hidePresets | hide-presets | Hides the built-in list of preset ranges, leaving only the calendar. | boolean | false |
inline | inline | Render the picker inline — the presets, calendar and Apply/Cancel/Clear are always visible, with no trigger button or popout. Use it when the picker lives directly on the page (e.g. in a form) rather than behind a trigger. | boolean | false |
startName | start-name | The name used to submit the **start** date as its own form field. When both
start-name and end-name are set, the picker submits two fields
(start-name=startDate, end-name=endDate) instead of the single name. | string | undefined | — |
endName | end-name | The name used to submit the **end** date as its own form field. See
start-name. | string | undefined | — |
size | size | The size of the component. | 's' | 'm' | 'l' | 'm' |
placeholder | placeholder | Placeholder text to display within the control. | string | undefined | — |
required | required | Determines whether the control is required or not.
A required control is announced as such to assistive technology and, inside
a <nord-field>, drives the required indicator on the <nord-field-label>.
When using this property you need to also set “novalidate” attribute on a form element to prevent browser from displaying its own validation errors. | boolean | false |
readonly | readonly | Makes the component readonly, so that it is not editable. Readonly differs from disabled in that readonly fields are still focusable and will be submitted with a form. | boolean | false |
disabled | disabled | Makes the component disabled. This prevents users from being able to interact with the component, and conveys its inactive state to assistive technologies. | boolean | false |
name | name | The name of the form component. | string | undefined | — |
form | form | Gets the form, if any, associated with the form element. The setter accepts a string, which is the id of the form. | HTMLFormElement | null | — |
Field properties
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
label | label | Label for the control. Ignored when the control is wrapped in a
<nord-field>, which provides the label via <nord-field-label>. | string | '' |
hint | hint | Optional hint text shown with the control. Ignored inside a <nord-field>,
which provides it via <nord-field-description>. | string | undefined | — |
hintBelow | hint-below | Renders the hint below the control and any error instead of below the label. | boolean | false |
hideLabel | hide-label | Visually hide the label, but still expose it to assistive technologies. | boolean | false |
error | error | Optional error shown with the control. Ignored inside a <nord-field>,
which provides it via <nord-field-error>. | string | undefined | — |
hideRequired | hide-required | Visually hide the required indicator, but still expose the required state to assistive technologies. | boolean | false |
Slots
| Slot name | Description |
|---|---|
trigger | Optional custom trigger element (e.g. a filter chip or a nord-button) that opens the picker. Replaces the built-in trigger button when provided. |
Methods
| Method name | Parameters | Description |
|---|---|---|
show() => void | N/A | Open the picker programmatically. |
hide(moveFocusToToggle: unknown) => void | moveFocusToToggle: Move focus back to the trigger after closing. | Close the picker programmatically. |
focus(options?: FocusOptions) => void | options: FocusOptions | Move focus to the picker's trigger. |
blur() => void | N/A | Programmatically remove focus from the component. |
click() => void | N/A | Programmatically simulates a click on the component. |
| Event | Detail Type | Description |
|---|---|---|
input | NordEvent | Dispatched live as the pending range changes inside the popout. |
change | NordEvent | Dispatched when the committed range changes (Apply or Clear). |
open | NordEvent | Dispatched when the popout is opened. |
close | NordEvent | Dispatched when the popout is closed. |
CSS Properties
CSS Custom Properties provide more fine grain control over component presentation. We advise utilizing existing properties on the component before using these.
| Property | Description | Default |
|---|---|---|
--n-date-range-picker-trigger-min-inline-size | Controls the minimum inline size of the trigger. | 14rem |
--n-date-range-picker-popout-inline-size | Controls the inline size of the popout content. | — |
Dependencies
This component is internally dependent on the following components:
- <nord-button>
Button
Buttons are used for interface actions. Primary style should be used only once per section for main call-to-action, while other styles can appear more frequently.
- <nord-calendar>
Calendar
Calendar allows user to pick a date. It comes with built-in functionality that allows you to set a minimum and a maximum allowed date. Please note that the date must be passed in ISO-8601 format.
- <nord-icon>
Icon
Icons are used to provide additional meaning or in places where text label doesn’t fit. Icon component allows you to display an icon from the Nordicons library.
- <nord-input>
Input
Inputs are used to allow users to provide text input when the expected input is short. As well as plain text, Input supports various types of text, including passwords and numbers.
- <nord-popout>
Popout
Popouts are small overlays that open on demand. They let users access additional content and actions without cluttering the page.
- <nord-stack>
Stack
Stack component manages layout of immediate children along the vertical or horizontal axis with optional spacing between each child.
- <nord-visually-hidden>
VisuallyHidden
Visually hidden is used when an element needs to be available to assistive technologies like screen readers, but be otherwise hidden.