Skip to content

Pickers

DateRangePicker

Bit.BlazorUIDateTimeRangePicker

A BitDateRangePicker is a drop-down calendar for picking a start and an end date, where context such as the day of the week matters. It offers one-click presets, up to three months side by side, range limits and disabled days, an optional time picker, an optional Apply/Cancel step, an inline mode, full keyboard support and any culture or time zone.

Input & binding

How the range is written and typed, binding the BitDateRangePickerValue, the Apply and Cancel commit step, and the callbacks.

Formatting

DateFormat formats (and parses) each date - by default the culture's short date, plus the time with ShowTimePicker. ValueFormat joins them: {0} is the start, {1} the end. NoDateText replaces the --- of a date not picked yet.

DateFormat is a .NET date and time format string applied with the Culture, and it is used both ways: to write the field and, with AllowTextInput, to read typed text back. Its default is the culture's short date pattern, followed by the culture's time pattern in the TimeFormat's clock when ShowTimePicker is on. Set it when the field must show the time without the time picker, or a fixed layout whatever the culture.

ValueFormat (default Start: {0} - End: {1}) is a composite format string. While only the start is picked the field reads, for example, Start: 1/5/2025 - End: ---, which is where NoDateText shows; an empty value leaves the field empty so the Placeholder shows. For typed input it must hold {0} before {1} with some text between them, or no text can be read back.






Text input

AllowTextInput makes the field editable. Text must follow ValueFormat and DateFormat; --- leaves an end open and a reversed pair is swapped. Typed ranges obey every calendar restriction (see Validation for the messages).

The text is read when the field commits it - on Enter or when it loses the focus - not on every keystroke. The literal parts of ValueFormat are matched ignoring case, and an end left empty or written as NoDateText stays open, though not both ends. Without a DateFormat of its own, a picker with the time picker also accepts a bare date; a date typed without a time is at 00:00, the end included (a picked end day is at 23:59). Emptying the field clears the value.

Text that cannot be read, or a range the calendar would not allow (outside MinDate/MaxDate, with an end on a disabled day, shorter than MinRange, longer than MaxRange, or covering a disabled day under ExcludeDisabledDates), leaves the value as it was. The text stays in the field and the field is reported invalid to the cascading EditContext with InvalidErrorMessage, DisabledDateErrorMessage or OutOfRangeErrorMessage. Those messages are only shown inside an EditForm, so outside one, as on the pickers below, a refused text is simply not applied.

While the field is editable, opening the callout keeps the focus in it, and Enter and Space type rather than open; ArrowDown still opens. ReadOnly ignores typed text.




A typed range longer than the 7-day MaxRange is rejected as invalid:

Binding

The value of the component is a BitDateRangePickerValue holding a nullable StartDate and EndDate, so a half-picked range is representable. Use @bind-Value for two-way binding, or DefaultValue together with the OnChange callback for the uncontrolled mode.

The picker never edits the instance it was handed: every pick, preset, time change or clear assigns a new BitDateRangePickerValue, so @bind-Value always receives a fresh object and the instance the page holds is left as it was. A Value passed one way, with neither ValueChanged nor OnChange, cannot be changed by the user: picks and typed text are ignored. A value pushed in from code moves the calendar to its start date; one whose end is earlier than its start (after the start is clamped to MinDate/MaxDate) is replaced by a range holding only the start. Remember that a half-picked range is a valid value: check both dates before using it, as the Validation section does.

From: 1/17/2020 12:00:00 AM +01:00
To: 1/25/2020 12:00:00 AM +01:00

Apply & Cancel

AutoApply="false" adds Cancel and Apply buttons: the range the callout opened on is restored unless Apply commits the new one (Escape, the overlay or the close button roll back too). Apply is disabled while the range is half-picked. OnApply/OnCancel report the outcome; ApplyButtonText/CancelButtonText word the buttons. Picks still reach Value while open.

Use it when a change is costly - a report that reloads, a search that runs - and the user should be able to try ranges before committing one. Since the picks reach Value (and OnChange) as they are made, and a rollback reaches it again, run the costly work from OnApply, which is handed the committed range, rather than from the value's change. A cleared value can be applied. Apply is also disabled while the picker is Disabled or ReadOnly.

With AutoApply off, AutoClose is ignored: neither a second pick nor a preset closes the callout. OnCancel is raised only by the Cancel button; a callout dismissed any other way rolls back just the same and reports itself through OnClose alone. A Standalone picker has no callout to commit, so it never shows the buttons and applies every pick at once.

Current value: - to -
Last outcome: -

Events

OnSelectDate fires on every pick with the range as it stands, so the half-picked range (a start date and no end date yet) is reported too. OnChange fires only once the value itself changes, OnMonthChange reports the month the calendar navigated to however it got there (buttons, keyboard or a selection), OnClear follows the clear button, and OnOpen/OnClose bracket the callout.
  • OnSelectDate is raised for clicks and Enter/Space on a day only; presets raise OnPresetSelect, and typed text, the time spinners and the clear button raise neither.
  • OnChange (with ValueChanged) follows every change of the value whatever caused it: each of the two picks, a preset, a time change, typed text, the clear button and the rollback of an Apply/Cancel picker. Use it to react to the value; use OnSelectDate to react to the user's clicks.
  • OnMonthChange is handed the first day of the first month on screen, at midnight in the picker's TimeZone, and is not raised when the month stays the same.
  • OnOpen is raised once per opening, not for a click on the field of a callout already open; OnClose for every close, whatever caused it.
  • OnClick, OnFocus, OnFocusIn and OnFocusOut report the field itself. OnClick is raised after the callout has opened, also when OpenCallout opened it.



Feedback

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