MYDS Logo

    MYDS

    Beta

    Date Picker

    Allows users to select a date from an interactive calendar.

    Usage

    import { DatePicker } from "@govtechmy/myds-react/date-picker";
    export default () => <DatePicker />;

    Examples

    Size

    Use the size prop to change the checkbox size!

    Uncontrolled vs Controlled State

    To use the date picker in the uncontrolled state, set the defaultValue prop to the initial value of the date picker.

    To use the date picker in the controlled state, set the value prop to the current value of the date picker and provide an onValueChange event listener to handle the change.

    Uncontrolled

    Controlled

    Disabled

    There are many ways to interact with DatePicker disabled state. Date picker can be disabled entirely by setting the disabled prop to true.

    For a finer control on which dates to disable, you can pass a Matcher | Matcher[] that defines the rules for disabling dates.

    Disable all dates

    Disable dates before today

    Disable dates after today

    Disable dates outside of range

    Disable dates by days of week (eg. Saturday and Sunday)

    Disable dates by callback function (eg. disable every 13th of the month)

    Maximum and Minimum Year

    You can set the maximum and minimum year for the date picker by passing the minYear and maxYear props.

    Year Sort Order

    You can set the sorting order of the years in the year dropdown by passing the yearOrder prop.

    Ascending

    Descending

    Locale

    To support common locales, you can pass the locale prop to the date picker.

    Default value is English en. To switch to Bahasa Melayu, pass ms.

    English

    Bahasa Melayu

    Props

    DatePicker

    PropTypeDefault
    size
    enum
    small
    defaultValue
    boolean | indeterminate
    false
    value
    boolean | indeterminate
    false
    onValueChange
    (date: Date ) => void
    -
    placeholder
    string
    dd / mm / yyyy
    disabled
    boolean | Matcher | Matcher[]
    false
    maxYear
    number
    2099
    minYear
    number
    1900
    yearOrder
    asc | desc
    asc
    locale
    en | ms
    en

    On this page