本文へ移動
日本語

仕組み

Picks a time of day, 24-hour only. The trigger is the same filled field as the text input and date picker (clock button, a real input, clear button). The panel is a floating sheet with borderless columns of 36px rows and Now / OK pills; it is absolutely positioned inside the component, with no portal; it measures space once on open and flips above or aligns right if needed. Each column scrolls on its own and centers the selected item. Picks apply at once; after the hour changes, the minute moves to the nearest available one. Typed text such as 0930 or 9:30 is normalized on Enter or blur.

向いている場面

  • A time in a form: opening and closing times, booking time, scheduled publish time, shift start and end.
  • Times that fit fixed steps, such as one slot every 15 minutes: set minuteStep.
  • Allowed ranges or blocked periods: use min, max and disabledTime.
  • Next to a date picker, one choosing the day and the other the time.

向かない場面

  • Choosing a date: use a date picker; this value has no date.
  • 12-hour AM / PM time: this component is 24-hour only.
  • A duration such as “remind me 30 minutes before”: use a number input with a unit or a select.
  • Only three or five fixed times: a radio group or select shows them all faster.
  • An ancestor with overflow: hidden and no room above or below: the panel has no portal and would be clipped.

使い方

import { useState } from 'react'
import { TimePicker } from './TimePicker.jsx'

export function PickupTimeField() {
  const [time, setTime] = useState('')
  return (
    <div>
      <label htmlFor="pickup-time">Pickup time</label>
      <TimePicker
        value={time}
        onChange={setTime}
        minuteStep={15}
        min="09:00"
        max="18:00"
        // Closed for lunch from 12:00 to 13:00
        disabledTime={(hour) => hour === 12}
        name="pickupTime"
        inputProps={{ id: 'pickup-time', required: true }}
      />
    </div>
  )
}

プロパティ

プロパティ型既定値説明
valuestring—Controlled value, 'HH:mm' ('HH:mm:ss' with showSeconds), 24-hour. An empty string means none; invalid values count as empty.
defaultValuestring''Initial value when uncontrolled.
onChange(value: string) => void—Called on a pick, a typed confirmation, “Now” or clear (empty string). Picking from the list fires at once, without waiting for OK.
openboolean—Controlled: whether the panel is open.
defaultOpenbooleanfalseUncontrolled: initially open. Opening initially does not take focus.
onOpenChange(open: boolean) => void—Called when the panel opens or closes.
size'sm' | 'md' | 'lg''md'Trigger height 36 / 44 / 52px, radius 10 / 12 / 14px, font 14 / 15 / 16px. The panel size stays the same.
disabledbooleanfalseDisabled: the field stays filled without its hairline, the text is muted, and it cannot open.
invalidbooleanfalseRed hairline, a faint red fill, a red halo while focused, and aria-invalid on the input. The error text belongs to the surrounding form field.
placeholderstring—Placeholder showing the format. Defaults to 'HH:mm' ('HH:mm:ss' with showSeconds).
clearablebooleantrueShows a clear button when there is a value. When false, emptying the input restores the old value.
editablebooleantrueWhether the time can be typed. Pass false on touch screens so opening does not raise the keyboard.
showSecondsbooleanfalseAdds a seconds column; the value becomes 'HH:mm:ss'.
minuteStepnumber1Minutes per step, commonly 5 / 10 / 15 / 30. Typed minutes off the step are rejected.
secondStepnumber1Seconds per step; matters with showSeconds.
minstring—Earliest selectable time (inclusive), 'HH:mm' or 'HH:mm:ss'.
maxstring—Latest selectable time (inclusive), 'HH:mm' or 'HH:mm:ss'.
disabledTime(hour, minute, second) => boolean—Times returning true are faded, cannot be clicked or focused, are marked aria-disabled, and arrow keys skip them. second is always 0 when seconds are hidden.
showNowbooleantrueShows a “Now” pill in the panel footer. It is grayed out when now is not selectable.
namestring—Renders a hidden <input name> so native form submission carries the value, always in the standard format.
onInvalidInput(text, reason: 'format' | 'unavailable') => void—Called when typed text is not recognized (format) or is recognized but unavailable or off the step (unavailable). The old value has already been restored.
inputPropsInputHTMLAttributes—Passed to the visible <input>: id (for <label htmlFor>), required, aria-label, aria-describedby and so on.
labelsobject—Replaces built-in text (hour, minute, second, openList, openListWithValue, clear, dialog, now, ok, hintFormat, hintMin, hintMax, hintMinuteStep, hintSecondStep, hintUnavailable). Shallow-merged over the English defaults.
...restHTMLAttributes—className, style and other attributes go to the root, which fills its container by default. Use --ds-timepicker-z to change the panel layer (default 30).

アクセシビリティ

  • The input is a combobox with aria-haspopup="dialog"; the panel is a dialog, each column a named listbox, each item an option with aria-selected and aria-disabled when unavailable.
  • Down opens the panel and moves focus into the hour column; Up and Down change the value, Left and Right change column, Home and End jump, Space selects, Enter confirms, Escape closes and returns focus.
  • Only one item per column is in the tab order; unavailable items cannot be focused and arrow keys skip them.
  • The selected item is a solid accent pill in bold text with enough contrast; unavailable items are faded, cannot be focused, and carry aria-disabled so screen readers announce them as unavailable.
  • Typing errors are announced with role="alert" and say why: format, too early, off the step.
  • Use <label htmlFor> with inputProps.id, and point aria-describedby at your error text when invalid.
  • On touch, rows and footer pills are 44px high, and Escape closes only the panel, not an outer dialog.

モーション

The field's focus halo grows from 0 to 4px over 220ms. Panel enter 220ms ease-out (moves 6px and scales 0.96 to 1 from the corner touching the trigger, with a fade), exit 140ms ease-in. The newly chosen pill pops in (scale 0.8 to 1, 320ms spring); only the new pill moves and hover has no transition, so holding an arrow key leaves no trail. With reduced motion the panel only fades and nothing else moves.

プロジェクトに追加

プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。

TimePicker.jsxtime-picker.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

フォーム入力
「空き時間グリッド」は Pro に含まれます。解除するとプレビューが表示されます。
「図形のブール演算」は Pro に含まれます。解除するとプレビューが表示されます。
「カスケード選択」は Pro に含まれます。解除するとプレビューが表示されます。