Skip to content

Pickers

DatePicker

Bit.BlazorUIMonthPickerYearPickerDateTimePicker

A BitDatePicker picks a date, or a date and time, from a drop-down or inline calendar with day, month and year views. It supports min/max, disabled and highlighted dates, typed input, any culture, calendar and time zone, and the WAI-ARIA combobox and grid keyboard patterns.

Input, binding & culture

Date formats and typing a date, binding the value, cultures, calendars and localized texts, and time zones.

Date format & text input

DateFormat sets the pattern the value is written and read with (default: the culture's short date, plus its time). AllowTextInput lets the date be typed; the input then carries the expected pattern as its accessible description (DateFormatAriaDescription). Invalid text, a date out of range, a disabled date and a disallowed time fail validation with InvalidErrorMessage, OutOfRangeErrorMessage, DisabledDateErrorMessage and DisallowedTimeErrorMessage.

DateFormat is a .NET custom format string, written and read with the Culture (and its calendar). Without it the field uses the culture's short date pattern - plus the time where a time picker is shown, the culture's year-month pattern in the MonthPicker mode and yyyy in the YearPicker mode - and reads a typed date more freely: with the time left off (the day then keeps the time the picker holds), with or without the seconds, and in either clock format. A DateFormat you set is the only pattern a typed date is read with, so include the time in it if the time matters.

Without AllowTextInput the field is read-only and a click or Enter/Space moves the focus into the calendar. With it, the text is read on every keystroke, a click opens the calendar but leaves the focus in the field, and only ↓/↑ move it into the calendar. Text that is cleared sets the value to null. Without the custom messages the errors read "The {field} field is not valid.", "... is out of the allowed range.", "... is not an allowed date." and "... is not an allowed time.", where the field is DisplayName or the bound property's name. The messages go to the EditContext, so they show inside an EditForm, through ShowValidationMessage or a ValidationMessage (see Validation & messages).


Expected format: dd/MM/yyyy


Expected format: dd/MM/yyyy

Binding

Two-way bind with @bind-Value, or set DefaultValue and listen to OnChange.

The bound type is DateTimeOffset?. DefaultValue is only the starting value of an unbound picker (uncontrolled mode): the picker keeps its own value from then on and reports each change through OnChange. A bound Value wins over it. OnChange and ValueChanged fire for every change of the value, however it came - a picked day, the time picker, typed text, the clear button or a deselection (null) - while OnSelectDate (see Events) reports only what is picked in the calendar.

A value the picker produces carries the UTC offset of its TimeZone (the local one by default) for that date. A value bound in with any other offset is the same instant: it is converted into the TimeZone to be shown.


Selected date: 1/17/2020 12:00:00 AM +01:00




Changed date: -

Culture & localization

Culture supplies the names, the first day of the week, the formats and the calendar itself (the Persian one below is a calendar of its own). Every title and accessible name is a parameter, so the rest is localized too - the last picker sets them all. See CultureInfoHelper (opens in a new tab) for building a custom culture.

Left unset, Culture is CultureInfo.CurrentUICulture. The calendar of the culture decides the months and years the picker shows, navigates and reads typed text in, but the value stays an ordinary DateTimeOffset - a date picked in the Persian calendar is bound as the same day in the Gregorian one. A culture that writes right to left mirrors the picker on its own. The texts with a {0} (or {0} and {1}) placeholder, such as GoToNextYearTitle, MonthPickerToggleTitle or YearRangePickerToggleTitle, get the year, the month title or the year range formatted into them; SelectedDateAriaAtomic - what a screen reader hears when the selection changes - gets the value as the field writes it.





TimeZone

TimeZone is the zone the value is read and shown in: the selected day, the month the calendar opens on and the time. Time zone data differs per OS and runtime settings (e.g. InvariantTimezone, more info(opens in a new tab)).

Left unset, it is TimeZoneInfo.Local - the browser's zone in WebAssembly, the server's in a server-rendered app. A bound value is converted into the zone to be shown, whatever offset it carries, and a picked or typed date is stored with the zone's UTC offset for that date (so daylight saving time is taken into account). Set it when the dates belong to a place rather than to the person picking them, such as a venue's opening hours.


Default (local TimeZone):


Selected date:




"Dateline Standard Time" TimeZone:


Selected date:

Feedback

Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.