A time zone picker: offsets, cities and names in the reader's language, searchable.
$ pnpm dlx shadcn@latest add @dashral/time-zone-selectInstallation
$ pnpm dlx shadcn@latest add @dashral/time-zone-selectAdds the component, the components it builds on, its npm packages and the theme tokens it uses. Or by its full URL: https://dashral.com/r/time-zone-select.json
Usage
import { TimeZoneSelect } from "@/components/dashral/time-zone-select"
<TimeZoneSelect label="Time zone" defaultValue="local" onValueChange={(zone) => saveSetting("timeZone", zone)} />Using the npm package? Import from @dashral/ui/components/time-zone-select instead, here and in the examples; the rest is the same.
Examples
API reference
TimeZoneSelect
Also takes every prop of Combobox(opens in a new tab).
| Prop | Type | Default |
|---|---|---|
label | ReactNodeShown above, linked to the control. | — |
description | ReactNodeA hint under the control. | — |
error | boolean | ReactNodetrue shows the error style; a message also shows under the control. | — |
labelAction | ReactNodeAt the end of the label's row, e.g. a “Forgot password?” link or the current value. | — |
withAsterisk | booleanMarks the label with an asterisk, e.g. alongside required. | false |
value | stringThe time zone, an IANA name ("Asia/Jakarta"), controlled. | — |
defaultValue | string | "local"The first one; "local" for the reader's own, once the page has loaded. | — |
onValueChange | (value: string) => voidCalled with the new value. | — |
timeZones | string[]Only these. | every zone the browser knows |
locale | stringFor the zones' names. | the LocaleProvider's |
placeholder / searchPlaceholder | stringAs on Combobox. | "Select a time zone" / "Search time zones…" |
classNames | { root, label, description, error, trigger, content, item }Classes for each part. | — |
className | stringExtra classes, merged with cn() so yours win. | — |
Keyboard
| Keys | Action |
|---|---|
| EnterorSpace | Open the list |
| Type | Search by city, region or name |
| ↓or↑ and Enter | Pick one |
Accessibility
- With label, description or error, the id, aria-describedby and aria-invalid are wired up for you.
- Each zone reads its offset and city ("GMT+07:00 Jakarta"), with its name in the page's language under it.