Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

Components / Inputs

DatePicker

Field that opens a Calendar (MUI X's DatePicker). ref points at the field's button.

import { DatePicker } from "@stylhero/ui";

Example

Code
import { DatePicker } from "@stylhero/ui";

function DatePickerExample() {
  return <DatePicker label="Delivery date" hint="Closed on Sundays." min={new Date()} isDateDisabled={(d) => d.getDay() === 0} clearable />;
}

Props

PropTypeDefaultDescription
className string -
clearable boolean - Shows an X to clear the value.
defaultValue Date | null null
disabled boolean -
error ReactNode -
format Intl.DateTimeFormatOptions { dateStyle: "medium" } Intl date format for the field.
hint ReactNode - Help text under the field. Replaced by error when set.
id string -
isDateDisabled (d: Date) => boolean - Return true to block a day (e.g. closed on Sundays).
label ReactNode -
locale string - BCP 47 locale for month and weekday names, e.g. "es-MX". Defaults to the browser's.
max Date -
min Date -
name string - Submits the value as YYYY-MM-DD (range: two fields, name[0] and name[1]).
onBlur FocusEventHandler<HTMLElement> - Runs when the field loses focus (react-hook-form's field.onBlur).
onValueChange (d: Date | null) => void -
placeholder string "Pick a date"
value Date | null -
weekStartsOn 0 | 1 - 0 = Sunday, 1 = Monday.

Takes a ref.

Keyboard

KeyDoes
Enter / SpaceOpens the calendar on the field's button
Arrow keysMove one day (left/right) or one week (up/down). Disabled days are skipped
Home / EndFirst / last day of the week
PageUp / PageDownPrevious / next month; with Shift, previous / next year
Enter / SpacePicks the focused day
EscCloses the calendar and returns focus to the field

Accessibility

  • The field is a button that announces the label and the picked date. ref points at it.
  • The label, hint and error are linked to the control (aria-describedby), and error sets aria-invalid.

Generated from src/components/DatePicker.tsx. Something wrong or missing? Open an issue.