A searchable time zone select built on the Bootstrap 6 Combobox. Visitors filter about 20 cities by name, country or live GMT offset. Pressing a letter on the closed select opens it and starts the search, and the arrow keys walk through the results. A warm clock card next to it shows the current time in the chosen zone. Use the pattern for any long select list: time zones, currencies, languages or projects.
How it works
The toggle is a <button class="form-control combobox-toggle"> with data-bs-toggle="combobox", data-bs-search="true", data-bs-search-normalize="true" (so "sao" finds "São Paulo") and data-bs-name="timezone". Bootstrap creates a hidden input with that name. The .menu sibling holds a .combobox-search input, .menu-header group titles and .menu-item buttons with data-bs-value set to an IANA zone such as Asia/Tokyo. Items stay direct children of .menu, because Bootstrap's Menu only moves arrow-key focus between direct children.
script.js imports Combobox and does five things:
- On load, it writes each zone's current offset into its
.ssc-offspan withIntl.DateTimeFormat, so offsets follow daylight saving time and typing "GMT+9" filters too. - After each search input,
syncGroups()hides a.ssc-group-headwhen none of its items match. The query also appears in.combobox-no-results. - A keydown listener on the toggle adds type-ahead: a printable key calls
show(), puts the character in the search field and focuses it. change.bs.comboboxupdates the clock card: local time, weekday, "Today"/"Tomorrow for you", the hour difference badge and a marker on the working-hours bar. The card refreshes every 30 seconds.- The
.ssc-pickbuttons click the matching option, so the Combobox value and hidden input stay in sync.
Customization
--ssc-accentand--ssc-accent-softon.ssc-root: change the orange accent, the selected option and the focus rings.--ssc-clock-bgand--ssc-work-coloron.ssc-root: recolor the clock card and its working-hours bar.- Add a
.menu-itemwithdata-bs-value="Europe/Madrid"and an empty.ssc-offspan; the offset fills in by itself. - Move
selectedandaria-selected="true"to another item to change the default zone. - Change
hour >= 9 && hour < 17inrenderClock(), and the.ssc-workposition in CSS, to match other working hours. - Edit the
data-ssc-pickvalues on the.ssc-pickbuttons to offer different shortcuts.
Use cases
- Scheduling and meeting tools: users search about 20 cities by name, country or GMT offset
- Account and profile settings: long lists such as time zones, languages or currencies stay easy to scan
- Remote team dashboards: a clock card shows the local time and hour difference for the chosen zone
- Forms with long option lists: grouped options and type-ahead let keyboard users find items fast
Accessibility
The label is tied to the toggle, which gets aria-expanded and aria-haspopup from Bootstrap, and selected options get aria-selected. Arrow keys, Home, End, Enter and Escape work, and focus returns to the toggle after a choice. The search field has its own aria-label. The clock card is a polite live region, and the shortcut buttons use aria-pressed. The caret and menu animations respect prefers-reduced-motion.
Bootstrap 6 notes
Bootstrap 5 developers would reach for a form-select plus a third-party library. Bootstrap 6 has the Combobox: a toggle button with a .menu, built on the new Menu component (formerly Dropdown), with .menu-item-check marks and .menu-item-description text. In 6.0.0-alpha.1 the console logs a harmless "more than one instance" warning for comboboxes. This is an alpha release, so APIs may change.