Time Picker

A time typed in a Time Input, or picked in columns — hour, minute, second, AM/PM — in a popover beside it: on the input's clock, locale and limits. For a range's end, how long it makes.

FormsExperimental

Usage

Usage

09:30:00

import { CdkOverlayOrigin } from '@angular/cdk/overlay';import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScInputGroup,  ScInputGroupAddon,  ScLabel,  ScPopover,  ScPopoverPortal,  ScPopoverProvider,

Anatomy

The picker holds your field: the Time Input — the value, the locale, the clock, the limits; put [formField] on it — and a button that opens the columns in a popover. Under them, if you want, a Now button and the duration.

import {  ScTimeInput,  ScTimePicker,  ScTimePickerColumns,  ScTimePickerDuration,  ScTimePickerNow,  ScTimePickerTrigger,} from '@semantic-components/ui';
<div scTimePicker>  <div scPopoverProvider [origin]="anchor">    <div scInputGroup cdkOverlayOrigin #anchor="cdkOverlayOrigin">      <div scTimeInput [formField]="form.time"></div>      <div scInputGroupAddon side="inline-end">        <button scTimePickerTrigger>…icon, name…</button>      </div>    </div>    <ng-template scPopoverPortal>      <div scPopover aria-label="Choose a time">        <div scTimePickerColumns></div>        <span scTimePickerDuration></span>        <button scTimePickerNow>Now</button>      </div>    </ng-template>  </div></div>

The columns

One column per part of the time input, in the locale's order — AM/PM first in Korean — the clock's left to right in any page. A pick sets that part at once, as typing does: an hour alone leaves the value empty until the minute is there. Outside minTime / maxTime, or before startTime, values can't be picked: an hour with no minute left, the minutes of the hour picked.

Closing — the same in every picker: each pick moves on to the next part — the hour to the minutes, the minutes to AM/PM, and the popover closes once the value is whole, focus back on the trigger. With [closeOnPick]="false" the picks still move on, but it stays open until Enter (keeping what is picked), Escape or a click outside. The arrow keys only browse. With confirm, nothing closes by itself: Apply (or Enter) keeps what is picked; Cancel, Escape or a click outside leave the value as it was before it opened.

The columns are written by the picker, from the locale: not markup of yours, and not styled from it — an option's look is the style's.

Keyboard

KeyDoes
↑ / ↓ The value before / after in the column: picked
Home / EndThe column's first / last value
← / → The column to the left / right, as they show
SpacePicks the focused value
EnterPicks it and closes
EscapeCloses, focus back on the button

Accessibility

  • The button is named by you, and says the popover is open (aria-expanded); the popover is a dialog, named by you.
  • Each column is a listbox named in the locale's words (hour, minute, AM/PM); its value selected, the ones out of range disabled.
  • It opens on the value, focus on the hour; closed, focus is back on the button.
  • The duration is said as it changes.
  • Typing in the field is always there: the columns are another way, not the only one.

Examples

Stays open

09:30:00

import { CdkOverlayOrigin } from '@angular/cdk/overlay';import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScInputGroup,  ScInputGroupAddon,  ScLabel,  ScPopover,  ScPopoverPortal,  ScPopoverProvider,

Apply

09:30:00

import { CdkOverlayOrigin } from '@angular/cdk/overlay';import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScInputGroup,  ScInputGroupAddon,  ScLabel,  ScPopover,  ScPopoverPortal,  ScPopoverProvider,

Hour cycle

import { CdkOverlayOrigin } from '@angular/cdk/overlay';import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScInputGroup,  ScInputGroupAddon,  ScLabel,  ScPopover,  ScPopoverPortal,  ScPopoverProvider,

Steps

10:15:00

import { CdkOverlayOrigin } from '@angular/cdk/overlay';import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScInputGroup,  ScInputGroupAddon,  ScLabel,  ScPopover,  ScPopoverPortal,  ScPopoverProvider,

Limits

10:00:00

import { CdkOverlayOrigin } from '@angular/cdk/overlay';import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScInputGroup,  ScInputGroupAddon,  ScLabel,  ScPopover,  ScPopoverPortal,  ScPopoverProvider,

Range

import { CdkOverlayOrigin } from '@angular/cdk/overlay';import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScInputGroup,  ScInputGroupAddon,  ScLabel,  ScPopover,  ScPopoverPortal,  ScPopoverProvider,

Now

No time.

import { CdkOverlayOrigin } from '@angular/cdk/overlay';import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScInputGroup,  ScInputGroupAddon,  ScLabel,  ScPopover,  ScPopoverPortal,  ScPopoverProvider,

Locale

14:30:00

import { CdkOverlayOrigin } from '@angular/cdk/overlay';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScInputGroup,  ScInputGroupAddon,  ScLabel,  ScPopover,  ScPopoverPortal,  ScPopoverProvider,

Disabled

import { CdkOverlayOrigin } from '@angular/cdk/overlay';import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScInputGroup,  ScInputGroupAddon,  ScLabel,  ScPopover,  ScPopoverPortal,  ScPopoverProvider,

Form

import { CdkOverlayOrigin } from '@angular/cdk/overlay';import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, FormRoot, form, required } from '@angular/forms/signals';import {  ScButton,  ScField,  ScFieldErrors,  ScInputGroup,  ScInputGroupAddon,  ScLabel,

RTL

import { Dir } from '@angular/cdk/bidi';import { CdkOverlayOrigin } from '@angular/cdk/overlay';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScInputGroup,  ScInputGroupAddon,  ScLabel,  ScPopover,  ScPopoverPortal,

API reference

Each part takes class, merged over its own (cn: a later class wins). The value, the clock and the limits are the Time Input's.

PartSelectorDescription
ScTimePickerdiv[scTimePicker] The root: reads its Time Input; the columns’ steps, a range’s start. exportAs scTimePicker: values(), enabled(part, value), pick(part, value), now(), close(), duration().
ScTimePickerTriggerbutton[scTimePickerTrigger] Opens and closes the columns: ghost in an input group (buttonSize), outline alone (variant). Write its icon and name.
ScTimePickerColumnsdiv[scTimePickerColumns] The columns, written from the locale: one per part, in its order. Opens on the value, focus on the hour.
ScTimePickerColumndiv[scTimePickerColumn] A column (a listbox), written by the columns — not one to place or style yourself: an option's look is the style's (timePicker.option).
ScTimePickerNowbutton[scTimePickerNow] The current time, on the steps — and closed: the style’s button (ghost, sm). Write its text.
ScTimePickerDuration[scTimePickerDuration] How long from startTime to the value, in the locale’s words (Intl.DurationFormat); empty without a start. aria-live.
ScTimePickerApply / Cancelbutton[scTimePickerApply], button[scTimePickerCancel] confirm: Apply keeps what is picked (disabled until the value is whole); Cancel puts back the value from before — closed either way. The style’s buttons; your text.
InputTypeDefaultDescription
closeOnPickbooleantrue Each pick moves on to the next part; the popover closes once the value is whole. False: it stays open until Enter, Escape or a click outside.
confirmbooleanfalse Nothing closes by itself: Apply (or Enter) keeps what is picked; Cancel, Escape or a click outside put back the value from before.
minuteStepnumber1 Minutes between the minute column’s values.
secondStepnumber1 Seconds between the second column’s values.
startTimeTemporal.PlainTime— A range’s start: earlier times can’t be picked; the duration counts from it.