Pickers
CircularTimePicker
Bit.BlazorUI
A BitCircularTimePicker picks a single time from an analog clock dial: an hour ring the pointer snaps to, then a minute ring and an optional second ring, with an AM/PM pair in 12-hour mode. It can be driven with a pointer or entirely from the keyboard, restricted to a range or a step, edited as text, laid out portrait or landscape, and rendered either inline or in a callout that becomes a sheet on small screens.
Picker, input & binding
Working the callout and the field: the now, clear and close buttons, the open state, typing a time and formatting it, binding the value, and cultures.
Picker actions
ShowNowButton jumps to the current time - snapped to the steps and clamped into the range, so it
can never land on a time the dial itself refuses - and ShowClearButton empties the picker.
ShowCloseButton adds a dismiss button in the corner of the callout, and AutoClose closes it
as soon as the selection is complete, without waiting for either - AutoCloseDelay holds the clock
open for a moment first, so the pick that completed it can be seen being made. Their captions are set
with NowButtonText, ClearButtonText and CloseButtonTitle.
- The now and clear buttons sit in a row under the clock and work on a standalone picker too; the close button and AutoClose are ignored there, as there is no callout.
- Now sets every part at once, so it completes the selection by itself. A picker without the seconds gets zero seconds (or the first second the range allows), and where the constraints leave no time to land on, the button changes nothing.
- Clear is disabled while the picker is empty. It sets the value to null, moves the dial back to its start view, raises OnClear and puts the focus on the dial.
- The selection is complete once the last part the dial offers is picked - the minute, or the second with ShowSeconds - or the single part of an OnlyHours / OnlyMinutes / OnlySeconds picker. AutoCloseDelay is in milliseconds (0 by default); a further pick inside the wait starts it over, and switching to another part cancels it.
- The now and clear buttons are disabled on a disabled or read-only picker.
Select hour
131415161718192021222300010203040506070809101112
Select hour
131415161718192021222300010203040506070809101112
Select hour
131415161718192021222300010203040506070809101112
Select hour
131415161718192021222300010203040506070809101112
Open state
@bind-IsOpen puts the callout under the control of the page, so it can be opened and closed
from anywhere - the OpenCallout and DismissCallout methods do the same from code.
DropDirection chooses the sides the callout may open towards: TopAndBottom (the default)
keeps it above or below the field, while All lets it take whichever side has the room. OnOpen
and OnClose report every change either way, a change pushed in through IsOpen included.
The open callout is a modal dialog over a transparent overlay: opening it puts the focus on the dial
(unless AllowTextInput keeps it in the field for typing), Tab and Shift + Tab cycle
through the parts inside it, and a click on the overlay closes it. A close the person makes - Escape, the
close button, the overlay, AutoClose - hands the focus back to the field so the keyboard carries
on where it left off; a close from code (DismissCallout, or IsOpen set to false) leaves the
focus where that code put it. When the focus leaves both the field and the callout some other way - a
Tab out of an editable field, which keeps the focus while the callout is open - the callout closes and
leaves the focus where it went: the callout is moved to the end of the document while it is open, so a picker left open behind
would be one nothing on the page could reach any more. Opening another callout closes this one too.
OpenCallout does nothing on a picker that is already open, disabled or standalone, and does not
raise OnClick.
Select hour
131415161718192021222300010203040506070809101112
Select hour
131415161718192021222300010203040506070809101112
Text input & value format
ValueFormat is the .NET format string the field is written with. Left unset, the picker writes
the time the way its culture does: the pattern of the culture, rewritten into the clock format the dial
is in (TimeFormat), extended with the seconds where ShowSeconds is set and padded with
leading zeros.
AllowTextInput makes the field editable, so a time can be typed instead of dialled. It is read
back with the same format - which is why the format is worth putting in the placeholder - except that
the default one also accepts a time written without its leading zeros.
- A ValueFormat you set is used exactly as given, to write and to read: ShowSeconds adds
nothing to it, and a format that disagrees with TimeFormat (
HH:mmon a 12-hour dial) writes the field the way the format says while the dial keeps its own face. The designators ofttand the separators come from the Culture (see the Culture sample). - The typed text is read as it is typed. Text that cannot be read, a time outside MinTime / MaxTime and a time the Allowed* predicates rule out each fail validation with a message of their own (see Validation); the steps are not applied to typed text. A time that reads correctly updates the dial at once, and an emptied field sets the value to null.
- An editable field keeps the focus when the callout opens, so the typing can go on; Enter and Space belong to the text there, and the callout is opened with a click, ↓ or ↑. ReadOnly makes the field read-only again.
Select hour
123456789101112
Select hour
131415161718192021222300010203040506070809101112
Binding
@bind-Value keeps a TimeSpan? in step with the dial in both directions. Where the value
does not need to be held anywhere, DefaultValue seeds the picker once and OnChange reports
every change from then on, so the picker keeps its own state (uncontrolled mode).
The value is a time of day. A TimeSpan that runs past a day or before its start - the result of
a subtraction, say - is shown as the time of day it lands on (26:30 as 02:30), and every pick writes a
time inside one day back. A dial pick always produces a whole time: the parts not picked yet count as
zero, so the first hour picked on an empty picker is already a value. The seconds of a bound value are
kept on a picker that does not show them. OnChange follows the value; OnSelectTime,
described with the other callbacks under
Events, follows the dial.
Select hour
131415161718192021222300010203040506070809101112
Selected time: 05:12:00
Select hour
131415161718192021222300010203040506070809101112
Changed time:
StartingValue is not a value: the picker below stays empty and submits nothing until it is
touched. It is only where the first change lands, so moving the hour keeps the 30 minutes instead of
resetting them to midnight - which is what a picker that mostly gets times around the working day wants.
Open both and dial an hour to see the difference.
Select hour
131415161718192021222300010203040506070809101112
Select hour
131415161718192021222300010203040506070809101112
Culture
Culture is what the value is formatted and parsed with, and what the AM/PM designators of the
12-hour toolbar are taken from; left unset it follows CultureInfo.CurrentUICulture. Our
CultureInfoHelper
(opens in a new tab) class shows how to build a custom one. The face itself is a deliberate choice rather than a
consequence of the culture - TimeFormat stays where it is put - but the short time pattern of a
culture says which of the two its readers expect, so a picker that should follow them can be wired to it
in a line.
Without a ValueFormat, the culture's own time pattern is what the field is written and read with -
its order, its separators and its designators, rewritten into the face of the picker. The numbers of the
dial and the read-out of the toolbar are always written with the digits 0-9 and padded to two digits,
whatever the culture. On a 12-hour dial the keyboard switches the half of the day with A and
P, and also with the first letters of the culture's two designators where those differ. The
culture sets no direction: a right-to-left layout is Dir's job (see
RTL).
Select hour
123456789101112
Select hour
123456789101112
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.