An input component that allows selecting a date from a popup calendar.
The component can be imported via:
The PlumaDatePicker component uses the @internationalized/date
package for handling date values. This means it expects CalendarDate
instances in the value prop, and returns them in the onChange callback as well.
A CalendarDate can be created using its constructor:
Or by parsing an ISO 8601 formatted string with the parseDate function:
When withTime is enabled, the component will return ZonedDateTime instances that include time and timezone information.
See the CalendarDate documentation or the ZonedDateTime documentation for more details.
A native Date object can be converted to a CalendarDate like this:
A CalendarDate can be converted back to a native Date object with the toDate method, for example:
For more information, see the CalendarDate conversion docs.
To use the date picker, at a minimum you must provide the following props:
value
CalendarDate or ZonedDateTime instanceonChange
CalendarDate or ZonedDateTime instance for the date selected in the calendarlabel
PlumaDatePicker extends from the PlumaTextField component, and also accepts
ariaLabel as an alternative (see PlumaTextField docs for more details on accessibility)For example:
The date picker supports selecting date ranges, which can be enabled
by setting the isRange prop to true.
When enabled, the value prop should be an object with start and end properties,
each containing a CalendarDate instance.
Similarly, the value in the onChange callback will also be an object of that shape.
You can constrain the selectable dates in two ways:
The simplest approach is to use the minDate and maxDate props to define a valid date range.
Dates outside this range will be disabled and visually indicated. Users will not be able to select dates outside the specified range.
You can use either one or both constraints:
minDate to enforce a minimum selectable date with no upper limitmaxDate to enforce a maximum selectable date with no lower limitBoth minDate and maxDate accept a CalendarDate instance:
You can also use just one constraint if needed:
These constraints also work with date ranges:
For more complex date constraints, you can use the isDateDisabled function prop. This gives you complete control over which dates are selectable.
The isDateDisabled function takes a CalendarDate parameter and should return true if the date should be disabled, or false if it should be enabled. It will take precedence over the minDate and maxDate props.
Important notes about date constraints:
isRange={true}), both the start and end dates must fall within the allowed range.value that contains dates outside the allowed range, they will still be displayed, but the user will be unable to select new dates outside the range.minDate and maxDate are inclusive - users can select the exact date specified as the min/max boundary.To make it easier to select common date ranges, the date picker supports
a withPresets prop, which will render a list of presets next to the calendar.
This is only available when isRange is true.
The list of presets shown can be customized, by passing an array of preset objects
into the presets prop.
A preset object can be one of two types: relative or custom.
A relative preset requires:
type: 'relative'
label
timeAgo
timeAgo should contain two properties:
unit
DateTimeDuration type),
one of 'years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds'.value
unit to go back from todayA custom preset allows for more flexibility in creating the date range. It requires:
type: 'custom'labelcallback
start and end properties, each containing a CalendarDate instance.
This range will be set when the preset is clicked.localTimeZone - a string representing the current time zone (either the local time zone, or the one set via the DatePicker's timeZone prop)The default presets and preset types can also be imported from Pluma via:
By default, presets will be automatically disabled if their resulting date range
falls (even partially) outside the date constraints set by minDate and maxDate.
However, sometimes it's desirable to have the presets enabled anyway, allowing the selection
of partial ranges.
The isPresetDisabled boolean can control this behavior. It can receive either:
By default, the date picker allows selecting a range of any length - including a single day.
To enforce a minimum and/or maximum range length, the minRange and maxRange props can be used.
Both props accept multiple formats:
"{quantity} {unit}", where unit is one of: days, weeks, months, years (e.g. "6 months", "2 weeks")@internationalized/date DateTimeDuration objectBy default, PlumaDatePicker will use the user's local time zone when working with dates:
most importantly, determining what "today" is for pre-selecting today's date, calculating relative ranges etc.
However, sometimes it's necessary to show a DatePicker that refers to dates in a different time zone.
To make sure the component handles disabled dates, presets, etc correctly, a localTimeZone string prop
can be provided.
The time zone string is passed into Intl API calls,
and should be an IANA time zone name.
If an invalid time zone is provided, it will fall back to @internationalized/date's getLocalTimeZone function.
If a string label is not sufficient, a component can be used to render the label.
In React, the label prop accepts any ReactNode.
If a string description is not sufficient, a component can be used to render the description.
In React, the description prop accepts any ReactNode.
If a string error is not sufficient, a component can be used to render the error.
In React, the error prop accepts any ReactNode.
PlumaDatePicker extends TextFieldElement (or elements) that describe the form field. Also used for error messages, as aria-errormessage isn't supported in all assistive technologies: https://a11ysupport.io/tech/aria/aria-errormessage_attribute
String value that labels the form field.
Element (or elements) that label the form field.
Focuses automatically when the component is rendered. Should be used with care and only sparingly, as there are some accessibility concerns. More information here
Additional classes to be applied to the top-level container. This is necessary as an argument in Ember, where we apply splattributes on the "input" itself, which means we can't pass a custom class to the containing element the classic way.
Whether the date picker should render in the open state.
A description for the field, providing additional context or hints.
An error message associated with the form field.
Boolean: Ember-only. If the error named block is used,
this prop can be set to true to indicate an error is present,
which will make the error block render.
Default:subtle
A color to apply to the icon.
An optional id to be assigned to the input element. Also used to generate ids for labels and error messages. If one isn't provided, it will be generated.
Whether the input should render in an "active" styled state.
Whether the input element is clearable.
Function to determine if a date is disabled and cannot be selected. This takes precedence over minDate and maxDate if provided.
Whether the form field is disabled.
Whether the form field is in an invalid state.
Whether the input should show a loading spinner.
By default, a preset will become disabled if its range cannot be fully selected
(based on dates being disabled via minDate and maxDate).
This allows overriding that behavior to enable/disable presets conditionally,
or keep them always enabled.
If a function is provided, it will be called with the preset and its calculated range,
and should return a boolean.
If the value is a boolean, it will apply to all presets.
Whether the date picker should select date ranges.
The label text to show with the form field.
By default, the DatePicker uses the user's local time zone for calculating dates like "today". If the date picker represents dates in a different time zone, a time zone name can be provided here.
The maximum selectable date.
The maximum range length that must be selected. By default, there is no maximum range length. It accepts multiple formats:
@internationalized/date DateTimeDuration objectThe minimum selectable date.
The minimum length of a time range that must be selected. By default, there is no minimum range length (essentially 0 - same day selection allowed). It accepts multiple formats:
@internationalized/date DateTimeDuration objectThe name attribute is used for HTML forms
The blur event handler for the input element.
Callback fired when the date selection changes.
In addition to isClearable, this function is required to render the clear button. This will be called when the clear button is clicked.
The focus event handler for the input element.
The input event handler for the input element.
Placeholder text to show inside the field.
The duration (in ms) for the popover animation.
Middleware options for the PlumaPopover component.
An array of presets to render instead of the default ones.
Whether to allow browser autofill and password managers. When false (default), adds attributes to disable password managers (1Password, LastPass, Bitwarden, Dashlane). Set to true for fields where autofill is desired (e.g., email, password, address fields).
Whether the generated description id should be included in the input's aria-describedby attribute.
Disable this when a label`` tag surrounds the input as well as it's description text, for example in an OptionCard` component.
Whether the generated label id should be included in the input's aria-labelledby attribute.
Disable this when the label tag surrounds the input as well as it's label text,
for example in an OptionCard component.
Default:true
Whether the calendar should automatically focus when it first renders.
Whether or not the password visibility button will be shown. Defaults to true.
By default, form elements will throw an error if no label or aria-label is provided. Disable this to suppress the error, for example when building a custom form element, and you want to handle labeling yourself.
Default:md
The size of the input element. medium and small are deprecated, use md and sm instead.
The type of input that should be rendered. Defaults to text.
Pluma internal property to set a component name used for logging. Only use if building a custom component that wraps this one and need to make it more obvious where errors, for example, come from.
Additional classes to be applied to the description element.
Additional classes to be applied to the error element.
Additional classes to be applied to the field node.
Ember-only: this is used internally to detect whether a label
named block is present, and to ignore empty label props if so.
Additional classes to be applied to the input node.
Sets the size attribute on the input element. This controls the visible width of the input in characters.
Additional classes to be applied to the div that wraps the input element.
Whether the component should render with "legacy" styles.
Additional classes to be applied to the label node.
Additional inline styles to apply on the popover component (the floating element, not the trigger). Should only be used as a last resort
The current date selection.
Whether to apply the center-baseline variant.
Whether the date picker should show preset selection.
Only available when isRange is true.
Default:false
Whether to include time selection in the picker.
Ember only: a modifier to apply on the input's wrapper element.
React only: a ref to the input's wrapper element.
The text to show for the preset button.
The time period (from now into the past) to select.
unit is an @internationalized/date DateTimeDuration key, one of:
'years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds'.
value is how many of that unit to go back.
The type of preset.
A callback function that returns the start and end dates for the preset.
The dates must be @internationalized/date CalendarDates.
The text to show for the preset button.
The type of preset.