Blazorise DatePicker component

DatePicker is an input field that allows the user to enter a date by typing or by selecting from a calendar overlay.

<DatePicker> is a fully featured date selection component that lets users select a date. DatePicker is based on a flatpickr datetime picker and as such is not a native date input element. That means that unlike DateEdit which will render type="date", DatePicker will render type="text" in the DOM.

Examples

Basic example

<DatePicker TValue="DateTime?" @bind-Date="@value" />
@code {
    DateTime? value;
}

Add icon

To add icon you can combine DatePicker with an Addon.
<Addons>
    <Addon AddonType="AddonType.Body">
        <DatePicker @ref="@datePicker" TValue="DateTime?" @bind-Date="@value" />
    </Addon>
    <Addon AddonType="AddonType.End">
        <Button Color="Color.Light" Clicked="@(()=>datePicker.ToggleAsync())">
            <Icon Name="IconName.CalendarDay" />
        </Button>
    </Addon>
</Addons>
@code {
    DatePicker<DateTime?> datePicker;

    DateTime? value;
}

Disable dates

If you’d like to make certain dates unavailable for selection you can assign the DisabledDates parameter.
<DatePicker TValue="DateTime?" DisabledDates="@disabledDates" />
@code {
    DateTime?[] disabledDates = new DateTime?[] {
        DateTime.Now.AddDays(-1),
        DateTime.Now.AddDays(2),
    };
}

Disable days

If you’d like to make only certain days in a week unavailable for selection you can assign the DisabledDays parameter.
<DatePicker TValue="DateTime?" DisabledDays="@disabledDays" />
@code {
    DayOfWeek[] disabledDays = new[]  {
        DayOfWeek.Saturday,
        DayOfWeek.Sunday,
    };
}

Range example

Select a range of dates using the range calendar.
<DatePicker TValue="DateTime?" @bind-Dates="selectedDates" InputMode="DateInputMode.Date" SelectionMode="DateInputSelectionMode.Range" />
@code {
    IReadOnlyList<DateTime?> selectedDates;
}

Multiple example

It is possible to select multiple dates.
<DatePicker @bind-Dates="selectedDates" TValue="DateTime?" InputMode="DateInputMode.Date" SelectionMode="DateInputSelectionMode.Multiple" />
@code{
    IReadOnlyList<DateTime?> selectedDates;
}

Inline Calendar

To always show the calendar you just need to set Inline parameter.
<DatePicker TValue="DateTime?" @bind-Date="@value" Inline />
@code {
    DateTime? value;
}

Non Static example

By default, the calendar menu will position statically. This means that it will also keep its position relative to the page when you scroll.

If you want to disable this behavior, you should assign the value false to the StaticPicker parameter.

<DatePicker TValue="DateTime?" @bind-Date="@value" StaticPicker="false" />
@code {
    DateTime? value;
}

Input format mask

In this example, the user is prompted to enter a value in the format dd.MM.yyyy.

Notice that we have also defined a DisplayFormat parameter. This is needed so that after the user finish with the input mask we need to properly parse it using the same format.

<DatePicker TValue="DateTime?" @bind-Date="@value" InputFormat="dd.MM.yyyy" DisplayFormat="dd.MM.yyyy" />
@code {
    DateTime? value;
}

Formats

Display Format

Native Flatpickr component has some special rules regarding the date format string. To make it easier to use we tried to map the flatpickr custom formatter to behave as close to .NET date format string.

Bellow you can find the list of available and supported mappings between Blazorise and flatpickr.

.NET value Flatpickr value Description
d j Day of the month without leading zeros, 1 to 31.
dd d Day of the month, 2 digits with leading zeros, 01 to 31.
ddd D A textual representation of a day, Mon through Sun.
dddd l A full textual representation of the day of the week, Sunday through Saturday.
M n Numeric representation of a month, without leading zeros, 1 through 12.
MM m Numeric representation of a month, with leading zero, 01 through 12.
MMM M A short textual representation of a month, Jan through Dec.
MMMM F A full textual representation of a month, January through December.
y y A two digit representation of a year. 99 or 03.
yy y -||-
yyy Y A full numeric representation of a year, 4 digits, 1999 or 2003.
yyyy Y -||-
yyyy Y -||-
H H Hours (24 hours), 00 to 23.
HH H -||-
h h Hours, 1 to 12.
hh G Hours, 2 digits with leading zeros, 01 to 12.
m i Minutes, 00 to 59.
mm i -||-
s s Seconds, 0, 1 to 59.
ss S Seconds, 2 digits, 00 to 59.
t K AM/PM designator.
tt K -||-

Input Format

We use the Inputmask library for handling of the datetime edit masks.

Bellow you can find the list of available and supported mappings between Blazorise and Inputmask.

.NET value Inputmask value Description
d d Day of the month as digits; no leading zero for single-digit days.
dd dd Day of the month as digits; leading zero for single-digit days.
ddd ddd Day of the week as a three-letter abbreviation.
dddd dddd Day of the week as its full name.
M m Month as digits; no leading zero for single-digit months.
MM mm Month as digits; leading zero for single-digit months.
MMM mmm Month as a three-letter abbreviation.
MMMM mmmm Month as its full name.
yy yy Year as last two digits; leading zero for years less than 10.
yyyy yyyy Year as 4 digits.
h h Hours; no leading zero for single-digit hours (12-hour clock).
hh hh Hours; leading zero for single-digit hours (12-hour clock).
HH HH Hours; leading zero for single-digit hours (24-hour clock).
m M Minutes; no leading zero for single-digit minutes. Uppercase M unlike CF timeFormat's m to avoid conflict with months.
mm MM Minutes; leading zero for single-digit minutes. Uppercase MM unlike CF timeFormat's mm to avoid conflict with months.
s s Seconds; no leading zero for single-digit seconds.
ss ss Seconds; leading zero for single-digit seconds.
t T Single-character time marker string: A or P.
tt TT Two-character time marker string: AM or PM.

Best Practices

Show the Date Format

Use a placeholder or helper to show how the input should be formatted. For example, "12/6/2020" represents different dates for Americans and Europeans.

Helpers are preferable to placeholders, as they are always visible. Fields with placeholders are also less noticeable than empty fields, so they are susceptible to being skipped. Use placeholders when space is limited, for example when Date Picker is used as a filter in a data grid header.

Format: DD/MM/YYYY
<Field>
    <FieldLabel>Start date</FieldLabel>
    <FieldBody>
        <DatePicker TValue="DateTime?" Placeholder="DD/MM/YYYY" />
    </FieldBody>
    <FieldHelp>Format: DD/MM/YYYY</FieldHelp>
</Field>

API

Attributes

Name Description Type Default
Date Gets or sets the input date value. TValue default
DateChanged Occurs when the date has changed. EventCallback<TValue>
DateExpression Gets or sets an expression that identifies the date value. Expression<Func<TValue>>
InputMode Hints at the type of data that might be entered by the user while editing the element or its contents. DateInputMode Date
SelectionMode Defines the mode in which the dates can be selected. DateInputSelectionMode Single
Min The earliest date to accept. DateTimeOffset? null
Max The latest date to accept. DateTimeOffset? null
Pattern The pattern attribute specifies a regular expression that the input element’s value is checked against on form submission. string null
Placeholder Sets the placeholder for the empty date. string null
Step The step attribute specifies the legal day intervals to choose from when the user opens the calendar in a date field. int 1
FirstDayOfWeek Defines the first day of the week in the calendar. DayOfWeek Sunday
DisplayFormat Defines the display format of the date input. string null
InputFormat Defines the input format mask of the date input. string null
TimeAs24hr Displays time picker in 24 hour mode without AM/PM selection when enabled. bool false
DisabledDates List of disabled dates that the user should not be able to pick. IEnumerable<TValue> null
DisabledDays List of disabled days in a week that the user should not be able to pick. IEnumerable<DayOfWeek> null
Inline Display the calendar in an always-open state with the inline option. bool false
DisableMobile If enabled, it disables the native input on mobile devices. bool true
Dates Gets or sets the input date value. IReadOnlyList<TValue>
DatesChanged Occurs when the date has changed. EventCallback<IReadOnlyList<TValue>>
DatesExpression Gets or sets an expression that identifies the date value. Expression<Func<IReadOnlyList<TValue>>>
RangeSeparator Overrides the range separator that is used to separate date values when SelectionMode is set to DateInputSelectionMode.Range. string
StaticPicker If enabled, the calendar menu will be positioned as static. bool true
On this page