Skip to content

Extras

TimeZonePicker

Bit.BlazorUI.ExtrasTimeZoneSelectorTimeZoneSelectTzPicker

BitTimeZonePicker picks a time zone out of a searchable list that shows the offset from UTC, the place and the country of each one - for the time zone of a profile, a meeting or a report, and for the TimeZone of the date and time pickers. Value is a TimeZoneInfo or the IANA id of the time zone, whichever it is bound to; the list is the same on every runtime, Windows ids and renamed IANA ids are recognized, the visitor's own time zone can be preselected from the browser, and the whole field is keyboard and screen-reader operable.

Events, forms & accessibility

The events the picker raises, opening it and picking a time zone from code, posting it with a plain HTML form, translating its texts, and keyboard and screen-reader support.

Events

OnChange reports the picked time zone, OnOpen / OnClose follow the list, OnSearch reports the search term, and OnFocus / OnBlur follow the field.

Selected time zone:
Search text:
Callout: closed
Field: blurred

Programmatic control

IsOpen is two-way bindable, and a reference offers OpenAsync, CloseAsync, SelectTimeZoneAsync (by any id, or by a TimeZoneInfo, raising the same events picking it in the list does), SelectedTimeZone and FocusAsync.



IsOpen: False
SelectedTimeZone:

Form submission

For a plain HTML form, Name posts the canonical IANA id of the selected time zone through a hidden field - whether the picker is bound to the id or to a TimeZoneInfo.

Posted as timeZone:

Localization

Every text the picker shows or announces can be translated. The names of the places and the countries come from TimeZones - new BitTimeZone instances carrying the ids of the built-in ones; the search box and the empty result take SearchBoxPlaceholder, SearchBoxAriaLabel and NoResultsText; and SearchResultsAnnouncement phrases the result count a screen reader hears.

Accessibility

The field is a native button with the combobox role: Tab reaches it, and Enter, Space, ArrowDown and ArrowUp open the list, as Home and End do on its first and last time zone. It carries aria-haspopup="listbox" and aria-expanded, and aria-controls names the list while it is open. The list is a listbox of option rows, the selected one marked with aria-selected="true". It is moved to the end of the page while open, and the root claims it back through aria-owns.

Label names both the field and the list through aria-labelledby. AriaLabel names them instead, for a field with no visible label, and wins over the Label; with neither, the field is named "Time zone" and the list "Time zones". The field and every row put a comma only a screen reader reads between the offset, the place and (in a row) the country, so a row reads "UTC+03:30, Tehran, Iran" rather than running together. The field and each row also carry that line in full as their tooltip.

When the list opens, the focus moves into its search box: a combobox too, named by SearchBoxAriaLabel, else the SearchBoxPlaceholder, else "Search time zones". Its aria-activedescendant follows the arrow keys and Page Up and Page Down (ten rows at a time); Home and End stay with its caret. Enter picks the active time zone and Escape closes the list, both giving the focus back to the field, as a click outside the list does; Alt+ArrowUp closes it the way Escape does. Tab moves on to what follows the field and closes the list, Shift+Tab goes back to the field and leaves it open, and the list also closes once the focus moves anywhere else.

With NoSearchBox the focus stays on the field, which carries the aria-activedescendant itself: Space picks as Enter does unless it falls inside a name being typed, Alt+ArrowUp picks the active time zone as it closes the list, Tab closes the list and moves on, and the letters and digits typed on the field, open or closed, jump to the time zone whose name they start.

A polite status region outside the list says what is otherwise only seen: the result count of a search ("12 time zones found", or NoResultsText for none, worded by SearchResultsAnnouncement when it is set), an ErrorMessage as it appears, and with NoSearchBox the time zone just picked. Required writes aria-required and keeps its asterisk from being read out, ReadOnly writes aria-readonly, an invalid value aria-invalid, and Disabled the native disabled with aria-disabled. In forced-colors mode the selected row takes the Highlight colors and the active row an outline.

Try both with the keyboard alone: the first has no visible label, the second no search box.

Feedback

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