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.

Events & validation

The events, keyboard and screen-reader support, validation and its messages, and opening and closing the callout from code.

Events

OnSelectDate reports each picked date and OnMonthChange the first day of the month the calendar moves to (handy for lazy-loading). OnClick, OnFocusIn, OnFocusOut, OnClear, OnOpen and OnClose report the rest, however they were triggered.
  • OnSelectDate receives the picked value with its time, or null when AllowDeselect clears it. Typing and the clear button do not raise it; OnChange reports every change of the value.
  • OnMonthChange fires whenever the day grid lands on another month - the arrows, the month and year pickers, go-to-today, the keyboard, or picking a day of another month - with the first day of that month (of the first month of a MonthCount strip).
  • OnClick fires when the field is activated - a click (also on an open picker), the keys that open it, or OpenCallout. It does not fire on a disabled or Standalone picker, or when a one-way bound IsOpen keeps the callout closed.
  • OnFocus, OnFocusIn and OnFocusOut follow the focus of the input itself, not of the calendar: opening the callout moves the focus into it.
  • OnClear fires for the clear button only.
  • OnOpen and OnClose fire once per opening and closing, including the ones driven by IsOpen; a click on an already open field raises no second OnOpen.


Selected date: -
Displayed month: -



Clicked: 0 times
Focused in: 0 times
Focused out: 0 times
Cleared: 0 times



Opened: 0 times
Closed: 0 times

Keyboard & screen readers

The input follows the WAI-ARIA combobox pattern: ↓/↑ - and Enter/Space on a field that is not typed into - open the calendar and move the focus into it, Esc closes it and returns the focus. The callout is a modal dialog that keeps the focus while open. In the day grid:

  • ← / →: previous/next day
  • ↑ / ↓: same day of the previous/next week
  • Home / End: first/last day of the week
  • PageUp / PageDown: same day of the previous/next month
  • Shift+PageUp / Shift+PageDown: same day of the previous/next year
  • Enter / Space: select the focused day

The month and year grids take the same keys (PageUp/PageDown move a year or a range of years), and the time fields step with PageUp/PageDown. Disabled cells are skipped. Every day is named with its full date, and the selection and displayed month are announced as they change.

In the month and year grids Home/End go to the first/last month of the year and the first/last year of the range. The arrow keys follow the reading direction, so → moves to the previous day in a right-to-left picker. Tab and Shift+Tab cycle inside the open callout; a click outside it closes it, and so does Tab from a field that kept the focus. On a field with AllowTextInput, Enter and Space stay with the text (Enter submits the form) and only the arrows open the calendar. Today carries aria-current="date" and the selected day aria-selected, and the texts a screen reader hears are all parameters (see Culture & localization).



Validation & messages

In an EditForm the picker validates like any input and sets aria-invalid. Description adds helper text, ErrorMessage shows a rejection the app decides itself (e.g. a server response) and Invalid marks the field without a message. Both are tied to the input through aria-describedby, the error is announced as it appears, and AriaDescription adds text for screen readers alone.

ShowValidationMessage shows the messages of the form under the picker, where ErrorMessage goes, so the form below needs no ValidationMessage component. The input is described by them through aria-describedby, so they are read out when it takes the focus, and an ErrorMessage of the app's own wins the place while it is set. They are not announced as they appear: a submit validates every field at once, and a message from each of them read out in a row would bury the form under its own errors. A BitParams holding a BitDatePickerParams with ShowValidationMessage turns it on for every picker inside it.

The templates: DescriptionTemplate replaces Description and ErrorMessageTemplate replaces ErrorMessage (and marks the picker invalid the same way), as the last picker shows. A template may render anything, so the live region announces ErrorMessageAriaLabel for it, or a bare "Invalid input" without one - give it the reason the template shows. ErrorMessageAriaLabel also gives the forced Invalid state something to announce.

The messages the picker adds itself for typed text are covered in Date format & text input; they name the field by DisplayName. NoValidate keeps the picker out of validation altogether.




Pick a weekday - we are closed on weekends.


Marked invalid by the app.
Dates are stored in UTC.


Booked: this date is already booked.
This date is already booked.
Bookings open three months ahead.
This date is already booked.

Programmatic control

Two-way bind IsOpen, or call OpenCallout and CloseCalloutAndFocus on a reference.

With @bind-IsOpen the app and the picker share the state: setting it opens or closes the callout (with OnOpen/OnClose, and the focus moved into the calendar on open, as a click does), and the picker writes it back whenever a click, a key, a selection or a click outside opens or closes it. A one-way bound IsOpen (no IsOpenChanged) hands the callout to the app alone: the picker never changes it, so clicks, Esc, AutoClose and the two methods leave it as set. OpenCallout opens the callout exactly as a click on the field does; CloseCalloutAndFocus closes it and returns the focus to the field - the call a button in CalloutFooterTemplate makes after setting the value. Both are safe to call from any thread and do nothing on a Standalone picker.


IsOpen: False

Feedback

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