本文へ移動
日本語
「ホイールピッカー」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

The wheel's position is one number in rows, --_p, written to the root's style on animation frames; every word works out its distance d from it in CSS. In the arc shape the start of a word is carried by −d × the step angle round a hub to the right of the words (the step is the row height divided by the radius), so the list curves like the edge of a dial, and the word itself tilts by only 45% of that angle, so long words do not lean into the next row; in the drum shape it turns round an axis behind the words with rotateX. Opacity falls with |d| to nothing just past the rows in view, and blur grows past the centre row. A drag follows the finger one row per row height with growing resistance past the ends. On release the speed over the last 90ms projects where a coast would stop; the wheel then approaches that whole row exponentially (time constant 0.26s), so it arrives quickly and settles softly on the detent. Scrolling turns it directly and settles when scrolling pauses. A press on a word turns the wheel to it, and with multiple ticks it. React renders only when the centred word changes, which also ticks a small accent mark in the centre band.

向いている場面

  • Choosing from a list that is long but well known: treatments, genres, cuisines, times, quantities.
  • Mobile sheets and booking flows, where a thumb flick is faster than scrolling a long list.
  • Filters where several words can be ticked without leaving the wheel.

向かない場面

  • Lists people need to search or compare: use a select or a multi-select with search.
  • Fewer than five options: show them all as chips or radios.

使い方

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

const treatments = ['Massage', 'Facial', 'Sauna', 'Steam room', 'Hot stones', 'Reflexology']

export function TreatmentPicker() {
  const [picked, setPicked] = useState(['Facial'])
  return <WheelPicker label="Treatments" items={treatments} multiple value={picked} onChange={setPicked} />
}

export function TimePicker({ slots }) {
  const [time, setTime] = useState(slots[0])
  return <WheelPicker label="Start time" items={slots} value={time} onChange={setTime} shape="drum" />
}

プロパティ

プロパティ型既定値説明
items(string | { value, label, disabled? })[]—The words in order. Plain strings are their own value.
multiplebooleanfalseSeveral choices: pressing a word, or Space on the centred one, ticks it. Off, the word the wheel rests on is the value.
value / defaultValue / onChangevalue | value[] / … / (next, changed) => void- / first item or [] / -Single choice: the value of the chosen word, set when the wheel comes to rest; setting it from outside turns the wheel there. Multiple: the ticked values, in list order.
onActiveChange(value, index) => void—Fires each time another word passes the centre, while the wheel is still moving.
defaultActivenumber0With multiple, the index of the word centred at first.
shape'arc' | 'drum''arc'arc: the words follow the edge of a large dial whose hub is to their right, each tilted along the curve. drum: they wrap round a cylinder and turn in depth.
rows / itemHeight / radiusnumber / number / number5 / 36 / by shapeRows in view, the height of one row in px, and the dial's or drum's radius in px (6.5 or 2.9 rows by default).
blurbooleantrueBlurs words with their distance from the centre. Off, they only fade.
labelstring—Accessible name of the list.
disabledbooleanfalseFades the wheel and ignores input.
...restHTMLAttributes—Other attributes go to the root <div>.

アクセシビリティ

  • The wheel is a listbox (aria-multiselectable with multiple) named by label; every word is an option with aria-selected, and aria-activedescendant follows the centred word.
  • Up and Down move one word, PageUp and PageDown a wheel's height, Home and End the ends; with multiple, Space or Enter ticks the centred word. Focus lights the centre band with a ring.
  • Ticked words show a filled check as well as darker text, so the choice is not carried by colour alone.
  • Touch: touch-action keeps sideways page gestures but gives vertical drags to the wheel; any word in view can be pressed directly.
  • Reduced motion drops the coast: the wheel follows a drag and then jumps to the nearest word, and keys and presses move it at once.

モーション

Coast after a flick: exponential approach with a 0.26s time constant to the projected row. Keys and presses: 0.10 to 0.15s time constant. Release without speed or end of scrolling: 0.10 to 0.12s. Centre mark: a 160ms tick on every word that passes. Tick: background fills over --ds-duration-fast and the circle pops on --ds-ease-spring.

プロジェクトに追加

Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。

WheelPicker.jsxwheel-picker.csstokens.cssREADME.md

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

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