Skip to main content

DatePicker: React

Allows users to enter a date. This can be done by either having the fill out the date via an input, but also provides the user with a calendar view for easier date selection.

Installation

Before you can start using the @mediahuis/chameleon-react component, you’ll need to install it, for more information check: Getting started for developers.

With that done, you’re now ready to implement the component in your application.

import { DatePicker } from '@mediahuis/chameleon-react';

export default function Example() {
const [date, setDate] = React.useState(new Date());

return (
<DatePicker
id="top"
label="Pick your date"
onChange={date => setDate(date)}
value={date}
/>
);
}

Properties

PropertyTypeDefaultRequiredDescription
actionReactNode-NoThe contents displayed within the ActionLabel.
classNameString-NoAllows extending the class names of the DatePicker component.
defaultMonthDate-NoThe initial month to show in the calendar.
disabledBoolean-NoSets the HTML disabled attribute.
disabledDaysMatcher-NoA react-day-picker modifier for greater control over disabled days.
errorBoolean-NoVisually displays the DatePicker with an error state. It also adds the necessary accessibility tags.
formatString'dd/MM/yyyy'NoThe format of the inputValue.
idString-YesSets the native HTML id attribute. It will also affect the label-id and the message-id for accessibility reasons.
inlineBoolean-NoMakes the DatePicker inline. It will stay open and not close automatically.
labelReactNode-YesThe contents displayed within the PrimaryLabel.
labelHiddenBoolean-NoThe `labelHidden` prop visually hides the label. Note that the label is still required for accessibility.
localeLocale-NoThe locale to be used in the Calendar.
maskString'99/99/9999'NoHelps the user with the input by ensuring a predefined format.
messageString-NoThe contents displayed beneath the input.
nameString-NoThe name of the form element.
optionalLabelString-NoThe contents displayed within the OptionalLabel.
pickerFooterString-NoText shown underneath the datepicker. It can be used to give hints or add extra information.
pickerInputOnlyBoolean-NoDetermines whether the DatePicker should only be controlled by the CalendarDialog.
placement'bottom-start' | 'bottom-end' | 'top-start' | 'top-end''bottom-start'NoSets the placement of the CalendarDialog against the TextField.
readOnlyBoolean-NoDetermines whether the DatePicker is read-only or not.
showOnFocusBoolean-NoDetermines whether the DatePicker calendar should show onFocus or not.
successBoolean-NoIndicates that the DatePicker is successfully filled in.
typeString-NoThe type of the input.
usePortalBoolean-NoThe value of the DatePicker.
valueDate-NoThe value of the calendar.
minDateDate-NoThe value of the calendar.

locale

Every brand has one fixed locale, but if your brand needs to use another locale it is possible to provide a custom locale.

Import and apply the locale

import { pt } from '@mediahuis/chameleon-react/locale';

// Pass the locale to the component
<DatePicker locale={pt} value={new Date()} />;

required

Chameleon form inputs are required by default, with the required attribute automatically set. To mark a field as optional, pass the optionalLabel prop to remove the required attribute.