ナビゲーション

v2.1.0
フォーム

ホイール

列を回し、選択マーカーの位置で値を選ぶピッカー。

このページの内容

ホイールでは、列を回して選択マーカーに合わせ、時、分、単位などの値を選びます。スマートフォンのピッカーをプラットフォームの標準機能で実現します。各列は、選択肢の一つが列の中央にスナップするスクロールコンテナーです。くぼんだ領域の中央を横切る小さなシートが、どの行が選択されているかを示します。

ホイール

<div class="wheel" role="group" aria-label="Reminder time">  <div class="wheel-column" role="listbox" aria-label="Hour" tabindex="0">    <div class="wheel-option" role="option" aria-selected="false">01</div>    <div class="wheel-option" role="option" aria-selected="false">02</div>    <div class="wheel-option" role="option" aria-selected="false">03</div>    <div class="wheel-option" role="option" aria-selected="false">04</div>    <div class="wheel-option" role="option" aria-selected="false">05</div>    <div class="wheel-option" role="option" aria-selected="false">06</div>    <div class="wheel-option" role="option" aria-selected="false">07</div>    <div class="wheel-option" role="option" aria-selected="false">08</div>    <div class="wheel-option" role="option" aria-selected="true">09</div>    <div class="wheel-option" role="option" aria-selected="false">10</div>    <div class="wheel-option" role="option" aria-selected="false">11</div>    <div class="wheel-option" role="option" aria-selected="false">12</div>  </div>  <span class="wheel-separator" aria-hidden="true">:</span>  <div class="wheel-column" role="listbox" aria-label="Minute" tabindex="0">    <div class="wheel-option" role="option" aria-selected="false">00</div>    <div class="wheel-option" role="option" aria-selected="false">05</div>    <div class="wheel-option" role="option" aria-selected="false">10</div>    <div class="wheel-option" role="option" aria-selected="false">15</div>    <div class="wheel-option" role="option" aria-selected="false">20</div>    <div class="wheel-option" role="option" aria-selected="false">25</div>    <div class="wheel-option" role="option" aria-selected="true">30</div>    <div class="wheel-option" role="option" aria-selected="false">35</div>    <div class="wheel-option" role="option" aria-selected="false">40</div>    <div class="wheel-option" role="option" aria-selected="false">45</div>    <div class="wheel-option" role="option" aria-selected="false">50</div>    <div class="wheel-option" role="option" aria-selected="false">55</div>  </div>  <div class="wheel-column" role="listbox" aria-label="Period" tabindex="0">    <div class="wheel-option" role="option" aria-selected="true">AM</div>    <div class="wheel-option" role="option" aria-selected="false">PM</div>  </div></div><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => attach(root.current!), [])  return (    <div ref={root} className="wheel" role="group" aria-label="Reminder time">      <div className="wheel-column" role="listbox" aria-label="Hour" tabIndex={0}>        <div className="wheel-option" role="option" aria-selected="false">01</div>        <div className="wheel-option" role="option" aria-selected="false">02</div>        <div className="wheel-option" role="option" aria-selected="false">03</div>        <div className="wheel-option" role="option" aria-selected="false">04</div>        <div className="wheel-option" role="option" aria-selected="false">05</div>        <div className="wheel-option" role="option" aria-selected="false">06</div>        <div className="wheel-option" role="option" aria-selected="false">07</div>        <div className="wheel-option" role="option" aria-selected="false">08</div>        <div className="wheel-option" role="option" aria-selected="true">09</div>        <div className="wheel-option" role="option" aria-selected="false">10</div>        <div className="wheel-option" role="option" aria-selected="false">11</div>        <div className="wheel-option" role="option" aria-selected="false">12</div>      </div>      <span className="wheel-separator" aria-hidden="true">:</span>      <div className="wheel-column" role="listbox" aria-label="Minute" tabIndex={0}>        <div className="wheel-option" role="option" aria-selected="false">00</div>        <div className="wheel-option" role="option" aria-selected="false">05</div>        <div className="wheel-option" role="option" aria-selected="false">10</div>        <div className="wheel-option" role="option" aria-selected="false">15</div>        <div className="wheel-option" role="option" aria-selected="false">20</div>        <div className="wheel-option" role="option" aria-selected="false">25</div>        <div className="wheel-option" role="option" aria-selected="true">30</div>        <div className="wheel-option" role="option" aria-selected="false">35</div>        <div className="wheel-option" role="option" aria-selected="false">40</div>        <div className="wheel-option" role="option" aria-selected="false">45</div>        <div className="wheel-option" role="option" aria-selected="false">50</div>        <div className="wheel-option" role="option" aria-selected="false">55</div>      </div>      <div className="wheel-column" role="listbox" aria-label="Period" tabIndex={0}>        <div className="wheel-option" role="option" aria-selected="true">AM</div>        <div className="wheel-option" role="option" aria-selected="false">PM</div>      </div>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'</script><div class="wheel" role="group" aria-label="Reminder time" {@attach attach}>  <div class="wheel-column" role="listbox" aria-label="Hour" tabindex="0">    <div class="wheel-option" role="option" aria-selected="false">01</div>    <div class="wheel-option" role="option" aria-selected="false">02</div>    <div class="wheel-option" role="option" aria-selected="false">03</div>    <div class="wheel-option" role="option" aria-selected="false">04</div>    <div class="wheel-option" role="option" aria-selected="false">05</div>    <div class="wheel-option" role="option" aria-selected="false">06</div>    <div class="wheel-option" role="option" aria-selected="false">07</div>    <div class="wheel-option" role="option" aria-selected="false">08</div>    <div class="wheel-option" role="option" aria-selected="true">09</div>    <div class="wheel-option" role="option" aria-selected="false">10</div>    <div class="wheel-option" role="option" aria-selected="false">11</div>    <div class="wheel-option" role="option" aria-selected="false">12</div>  </div>  <span class="wheel-separator" aria-hidden="true">:</span>  <div class="wheel-column" role="listbox" aria-label="Minute" tabindex="0">    <div class="wheel-option" role="option" aria-selected="false">00</div>    <div class="wheel-option" role="option" aria-selected="false">05</div>    <div class="wheel-option" role="option" aria-selected="false">10</div>    <div class="wheel-option" role="option" aria-selected="false">15</div>    <div class="wheel-option" role="option" aria-selected="false">20</div>    <div class="wheel-option" role="option" aria-selected="false">25</div>    <div class="wheel-option" role="option" aria-selected="true">30</div>    <div class="wheel-option" role="option" aria-selected="false">35</div>    <div class="wheel-option" role="option" aria-selected="false">40</div>    <div class="wheel-option" role="option" aria-selected="false">45</div>    <div class="wheel-option" role="option" aria-selected="false">50</div>    <div class="wheel-option" role="option" aria-selected="false">55</div>  </div>  <div class="wheel-column" role="listbox" aria-label="Period" tabindex="0">    <div class="wheel-option" role="option" aria-selected="true">AM</div>    <div class="wheel-option" role="option" aria-selected="false">PM</div>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template>  <div ref="root" class="wheel" role="group" aria-label="Reminder time">    <div class="wheel-column" role="listbox" aria-label="Hour" tabindex="0">      <div class="wheel-option" role="option" aria-selected="false">01</div>      <div class="wheel-option" role="option" aria-selected="false">02</div>      <div class="wheel-option" role="option" aria-selected="false">03</div>      <div class="wheel-option" role="option" aria-selected="false">04</div>      <div class="wheel-option" role="option" aria-selected="false">05</div>      <div class="wheel-option" role="option" aria-selected="false">06</div>      <div class="wheel-option" role="option" aria-selected="false">07</div>      <div class="wheel-option" role="option" aria-selected="false">08</div>      <div class="wheel-option" role="option" aria-selected="true">09</div>      <div class="wheel-option" role="option" aria-selected="false">10</div>      <div class="wheel-option" role="option" aria-selected="false">11</div>      <div class="wheel-option" role="option" aria-selected="false">12</div>    </div>    <span class="wheel-separator" aria-hidden="true">:</span>    <div class="wheel-column" role="listbox" aria-label="Minute" tabindex="0">      <div class="wheel-option" role="option" aria-selected="false">00</div>      <div class="wheel-option" role="option" aria-selected="false">05</div>      <div class="wheel-option" role="option" aria-selected="false">10</div>      <div class="wheel-option" role="option" aria-selected="false">15</div>      <div class="wheel-option" role="option" aria-selected="false">20</div>      <div class="wheel-option" role="option" aria-selected="false">25</div>      <div class="wheel-option" role="option" aria-selected="true">30</div>      <div class="wheel-option" role="option" aria-selected="false">35</div>      <div class="wheel-option" role="option" aria-selected="false">40</div>      <div class="wheel-option" role="option" aria-selected="false">45</div>      <div class="wheel-option" role="option" aria-selected="false">50</div>      <div class="wheel-option" role="option" aria-selected="false">55</div>    </div>    <div class="wheel-column" role="listbox" aria-label="Period" tabindex="0">      <div class="wheel-option" role="option" aria-selected="true">AM</div>      <div class="wheel-option" role="option" aria-selected="false">PM</div>    </div>  </div></template>
列をスクロールするか、タッチ画面でドラッグします。選択肢をクリックするか、列にフォーカスを当てて矢印キーを使うこともできます。

#プラットフォームの標準機能

  • 列の回転にはスクロールを使います。マウスホイール、指、トラックパッドで、通常のスクロールコンテナーと同じように操作できます。
  • 初期選択は、scroll-initial-target に対応していれば初回描画からマークに揃います。ほかのブラウザーではビヘイビアーの取り付け時に揃います。
  • 停止位置の調整にはスクロールスナップを使います。列に scroll-snap-type: y mandatory、各選択肢に scroll-snap-align: center を指定すると、列が 2 つの値の間で止まることはありません。両端に余白を設け、最初と最後の選択肢もマーカーまで移動できるようにします。
  • ホイールの見た目はスクロール駆動アニメーションで作ります。列内の選択肢はそれぞれ独自のビュータイムラインを持ち、中央では最も濃く表示され、中央から離れるほど薄くなり、わずかに奥へ傾きます。この描画のためにスクリプトでスクロール位置を読み取る必要はありません。

ビュータイムラインに対応していないブラウザーでは、すべての選択肢を傾けずに表示し、aria-selected="true" が付いた選択肢を濃い色で強調します。

#ビヘイビア

スタイルシートだけでは、マーカーに合った値をフォームに渡せません。wheel ビヘイビアは、列のスクロールが止まった時点でその値を読み取ります。ルートとして wheel クラスが付いた要素を受け取り、オプションはなく、ビヘイビアを解除する関数を返します。

app.js
import { wheel } from '@master/ui/behaviors/wheel.js'const root = document.querySelector('.wheel')wheel(root)root.addEventListener('change', (event) => {  // event.target is the column that came to rest.  console.log(event.target.getAttribute('aria-label'), event.detail.value)})
  • スクロールの停止。 列が停止すると、ビヘイビアは aria-selected="true" をマーカーの位置にある選択肢に移します。 scrollsnapchange が使える場合はブラウザーが返すスナップ先を使い、それ以外ではスクロール位置を読み取ります。
  • イベント。 選択肢が変わると、列はバブリングする input と change をこの順に発行します。どちらのイベントも、detail.value には選択肢の data-value、それがなければ選択肢のテキストが入り、detail.option には選択肢の要素が入ります。
  • 初期位置の設定。 ビヘイビアを適用したときや、ポップオーバーを開くなどして列のレイアウトが再計算されたときに、各列で選択済みの項目をマーカーの位置に合わせます。
  • クリック。 選択肢をクリックすると、その項目がマーカーの位置まで移動します。
  • キー操作。 フォーカスのある列では、リストボックスと同じキー操作で選択肢を 1 つずつ移動できます。
  • 無効な選択肢。 列が aria-disabled="true" の付いた選択肢で止まると、最も近い有効な選択肢まで移動します。

フォームで値を送信するには、change のリスナーで detail.value を非表示の入力にコピーします。 ビヘイビアーがなくても列はスクロールし、スナップします。scroll-initial-target に対応していれば選択済みの項目から、それ以外では最初の項目から始まります。aria-selected はマークアップで設定したままです。

#1 列

ホイールは 1 列でも使えます。wheel-sm は表示を 5 行から 3 行に減らすため、ポップオーバー内や設定項目の行に適しています。

1 列

<div class="wheel" role="group" aria-label="Repeat every">  <div class="wheel-column" role="listbox" aria-label="Interval" tabindex="0">    <div class="wheel-option" role="option" aria-selected="false">Hour</div>    <div class="wheel-option" role="option" aria-selected="false">Day</div>    <div class="wheel-option" role="option" aria-selected="true">Week</div>    <div class="wheel-option" role="option" aria-selected="false">Fortnight</div>    <div class="wheel-option" role="option" aria-selected="false">Month</div>    <div class="wheel-option" role="option" aria-selected="false">Quarter</div>    <div class="wheel-option" role="option" aria-selected="false">Year</div>  </div></div><div class="wheel wheel-sm" role="group" aria-label="Font size">  <div class="wheel-column" role="listbox" aria-label="Size" tabindex="0">    <div class="wheel-option" role="option" aria-selected="false">12</div>    <div class="wheel-option" role="option" aria-selected="false">13</div>    <div class="wheel-option" role="option" aria-selected="true">14</div>    <div class="wheel-option" role="option" aria-selected="false">15</div>    <div class="wheel-option" role="option" aria-selected="false">16</div>    <div class="wheel-option" role="option" aria-selected="false">18</div>    <div class="wheel-option" role="option" aria-selected="false">20</div>    <div class="wheel-option" role="option" aria-selected="false">24</div>  </div>  <span class="wheel-separator" aria-hidden="true">px</span></div><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => attach(root.current!), [])  return (    <div ref={root}>      <div className="wheel" role="group" aria-label="Repeat every">        <div className="wheel-column" role="listbox" aria-label="Interval" tabIndex={0}>          <div className="wheel-option" role="option" aria-selected="false">Hour</div>          <div className="wheel-option" role="option" aria-selected="false">Day</div>          <div className="wheel-option" role="option" aria-selected="true">Week</div>          <div className="wheel-option" role="option" aria-selected="false">Fortnight</div>          <div className="wheel-option" role="option" aria-selected="false">Month</div>          <div className="wheel-option" role="option" aria-selected="false">Quarter</div>          <div className="wheel-option" role="option" aria-selected="false">Year</div>        </div>      </div>      <div className="wheel wheel-sm" role="group" aria-label="Font size">        <div className="wheel-column" role="listbox" aria-label="Size" tabIndex={0}>          <div className="wheel-option" role="option" aria-selected="false">12</div>          <div className="wheel-option" role="option" aria-selected="false">13</div>          <div className="wheel-option" role="option" aria-selected="true">14</div>          <div className="wheel-option" role="option" aria-selected="false">15</div>          <div className="wheel-option" role="option" aria-selected="false">16</div>          <div className="wheel-option" role="option" aria-selected="false">18</div>          <div className="wheel-option" role="option" aria-selected="false">20</div>          <div className="wheel-option" role="option" aria-selected="false">24</div>        </div>        <span className="wheel-separator" aria-hidden="true">px</span>      </div>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'</script><div {@attach attach}>  <div class="wheel" role="group" aria-label="Repeat every">    <div class="wheel-column" role="listbox" aria-label="Interval" tabindex="0">      <div class="wheel-option" role="option" aria-selected="false">Hour</div>      <div class="wheel-option" role="option" aria-selected="false">Day</div>      <div class="wheel-option" role="option" aria-selected="true">Week</div>      <div class="wheel-option" role="option" aria-selected="false">Fortnight</div>      <div class="wheel-option" role="option" aria-selected="false">Month</div>      <div class="wheel-option" role="option" aria-selected="false">Quarter</div>      <div class="wheel-option" role="option" aria-selected="false">Year</div>    </div>  </div>  <div class="wheel wheel-sm" role="group" aria-label="Font size">    <div class="wheel-column" role="listbox" aria-label="Size" tabindex="0">      <div class="wheel-option" role="option" aria-selected="false">12</div>      <div class="wheel-option" role="option" aria-selected="false">13</div>      <div class="wheel-option" role="option" aria-selected="true">14</div>      <div class="wheel-option" role="option" aria-selected="false">15</div>      <div class="wheel-option" role="option" aria-selected="false">16</div>      <div class="wheel-option" role="option" aria-selected="false">18</div>      <div class="wheel-option" role="option" aria-selected="false">20</div>      <div class="wheel-option" role="option" aria-selected="false">24</div>    </div>    <span class="wheel-separator" aria-hidden="true">px</span>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template>  <div ref="root">    <div class="wheel" role="group" aria-label="Repeat every">      <div class="wheel-column" role="listbox" aria-label="Interval" tabindex="0">        <div class="wheel-option" role="option" aria-selected="false">Hour</div>        <div class="wheel-option" role="option" aria-selected="false">Day</div>        <div class="wheel-option" role="option" aria-selected="true">Week</div>        <div class="wheel-option" role="option" aria-selected="false">Fortnight</div>        <div class="wheel-option" role="option" aria-selected="false">Month</div>        <div class="wheel-option" role="option" aria-selected="false">Quarter</div>        <div class="wheel-option" role="option" aria-selected="false">Year</div>      </div>    </div>    <div class="wheel wheel-sm" role="group" aria-label="Font size">      <div class="wheel-column" role="listbox" aria-label="Size" tabindex="0">        <div class="wheel-option" role="option" aria-selected="false">12</div>        <div class="wheel-option" role="option" aria-selected="false">13</div>        <div class="wheel-option" role="option" aria-selected="true">14</div>        <div class="wheel-option" role="option" aria-selected="false">15</div>        <div class="wheel-option" role="option" aria-selected="false">16</div>        <div class="wheel-option" role="option" aria-selected="false">18</div>        <div class="wheel-option" role="option" aria-selected="false">20</div>        <div class="wheel-option" role="option" aria-selected="false">24</div>      </div>      <span class="wheel-separator" aria-hidden="true">px</span>    </div>  </div></template>

#選択マーカー

中央を横切るシートはホイール全体に属するため、時と分の列で同じシートを共有できます。シートはくぼみの縁から 4px 内側にあり、角の丸みは外側の輪郭と同心です。wheel-separator は 2 列の間でシートに重ねる固定テキストです。時刻のコロンや、数値の後に付く単位などを置けます。

行の高さはどのポインターでも 36px です。表示行数を増やすには、--wheel-rows に奇数を設定します。

#ほかのコンポーネントが適する場合

ホイールは、利用者が順序ごと覚えている少数の選択肢から、タッチ端末で値を選ぶのに適しています。キーボードとポインターでは、セレクトやステッパーの方が素早く操作できます。日付を選ぶなら、カレンダーで選択する日がどの週にあるかも確認できます。スマートフォンではネイティブの <input type="time"> で端末標準のホイールが開きます。ピッカーをページ内に組み込む必要がある場合は、このコンポーネントを使います。

#キーボード操作

ビヘイビアを適用すると、キー操作でフォーカスのある列が選択肢単位で移動し、無効な選択肢は飛ばします。ビヘイビアがない場合、同じキーで通常のスクロールコンテナーと同様に列がスクロールし、最後にスナップで位置が揃います。

キー操作
ArrowUp, ArrowDownフォーカスのある列をスクロールし、無効な選択肢を飛ばして、前または次の選択肢を目印の位置に合わせます。
PageUp, PageDownフォーカス中の列を1ページ分、表示されている選択肢の数だけスクロール
Home, Endフォーカス中の列を最初または最後の選択肢までスクロール

#アクセシビリティ

  • 各列は aria-label と tabindex="0" を持つ role="listbox" で、各選択肢は role="option" です。ビヘイビアは、マーカーの位置にある選択肢に aria-selected が付くように更新し、列の aria-activedescendant でその選択肢を示します。列は回している間もフォーカスを保つため、キー操作で移った選択肢をスクリーンリーダーが読み上げます。id のない選択肢には、ビヘイビアが id を付けます。
  • 選択肢の傾きと透明度は、利用者のスクロールに連動します。動きを抑える設定では、透明度の変化だけが残ります。

#React、Svelte、Vue

wheel コンポーネントは、データから列を描画し、ビヘイビアを適用して、各列の値を受け渡します。npx master-ui add wheel でプロジェクトにコピーできます。コンポーネントの構成と使い方は React、Svelte、Vue を参照してください。

ui/wheel.tsx
'use client'import { Fragment, useState, type ComponentProps } from 'react'import { wheel } from '@master/ui/behaviors/wheel.js'import { useBehavior } from './use-behavior'export interface WheelColumn {  /** The name of the column, for assistive technology. */  label: string  options: (string | { value: string, label: string, disabled?: boolean })[]  /** Fixed text after the column that rests on the mark: the colon of a time, a unit. */  separator?: string}export interface WheelProps extends Omit<ComponentProps<'div'>, 'defaultValue' | 'role' | 'ref'> {  columns: WheelColumn[]  /** The value of each column, in the order of the columns. */  value?: string[]  defaultValue?: string[]  onValueChange?: (value: string[]) => void}/** Columns that turn. Name the group with `aria-label` or `aria-labelledby`. */export function Wheel({ columns, value, defaultValue, onValueChange, className, ...root }: WheelProps) {  const ref = useBehavior(wheel, undefined, { value, defaultValue, onValueChange })  const [first] = useState(value ?? defaultValue ?? [])  return (    <div className={className ? `wheel ${className}` : 'wheel'} role="group" ref={ref} {...root}>      {columns.map((column, at) => (        <Fragment key={column.label}>          <div className="wheel-column" role="listbox" aria-label={column.label} tabIndex={0}>            {column.options.map((option) => {              const { value: own, label, disabled = false } = typeof option === 'string' ? { value: option, label: option } : option              return <div className="wheel-option" role="option" key={own} data-value={own} aria-selected={own === first[at]} aria-disabled={disabled || undefined}>{label}</div>            })}          </div>          {column.separator !== undefined && <span className="wheel-separator" aria-hidden="true">{column.separator}</span>}        </Fragment>      ))}    </div>  )}
ui/Wheel.svelte
<script lang="ts" module>  import type { HTMLAttributes } from 'svelte/elements'  export interface WheelColumn {    /** The name of the column, for assistive technology. */    label: string    options: (string | { value: string, label: string, disabled?: boolean })[]    /** Fixed text after the column that rests on the mark: the colon of a time, a unit. */    separator?: string  }  export interface WheelProps extends Omit<HTMLAttributes<HTMLDivElement>, 'role' | 'children'> {    columns: WheelColumn[]    /** The value of each column, in the order of the columns. Bind it, or leave it out. */    value?: string[]    onValueChange?: (value: string[]) => void  }</script><script lang="ts">  import { untrack } from 'svelte'  import { wheel } from '@master/ui/behaviors/wheel.js'  import { behavior } from './behavior.svelte.js'  let { columns, value = $bindable(), onValueChange, class: className, ...root }: WheelProps = $props()  // The first value is drawn into the first render; after that the behavior marks what is selected. An option  // written later, from new columns, is drawn with the value as it is then, which is not read as state.  const chosen = { values: untrack(() => value ?? []) }  const attach = behavior(wheel, undefined, {    value: () => value,    change: (next) => { chosen.values = next; value = next; onValueChange?.(next) },    settled: (held) => { chosen.values = held },  })  const plain = (option: WheelColumn['options'][number]) => typeof option === 'string' ? { value: option, label: option, disabled: false } : option</script><!--  @component  Columns that turn. Name the group with `aria-label` or `aria-labelledby`.--><div class={['wheel', className]} role="group" {@attach attach} {...root}>  {#each columns as column, at (column.label)}    <div class="wheel-column" role="listbox" aria-label={column.label} tabindex={0}>      {#each column.options.map(plain) as option (option.value)}        <div class="wheel-option" role="option" data-value={option.value} aria-selected={option.value === chosen.values[at]} aria-disabled={option.disabled || undefined}>{option.label}</div>      {/each}    </div>    {#if column.separator !== undefined}<span class="wheel-separator" aria-hidden="true">{column.separator}</span>{/if}  {/each}</div>
ui/Wheel.vue
<script lang="ts">export interface WheelColumn {  /** The name of the column, for assistive technology. */  label: string  options: (string | { value: string, label: string, disabled?: boolean })[]  /** Fixed text after the column that rests on the mark: the colon of a time, a unit. */  separator?: string}</script><script setup lang="ts">import { useTemplateRef } from 'vue'import { wheel } from '@master/ui/behaviors/wheel.js'import { useBehavior } from './use-behavior'defineOptions({ inheritAttrs: false })defineProps<{  columns: WheelColumn[]}>()/** The value of each column, in the order of the columns: `v-model`. */const model = defineModel<string[]>()/* Columns that turn. Name the group with `aria-label` or `aria-labelledby`. */const first = model.value ?? []const root = useTemplateRef<HTMLDivElement>('root')useBehavior(root, wheel, undefined, model)const row = (option: WheelColumn['options'][number]) => typeof option === 'string' ? { value: option, label: option, disabled: false } : option</script><template>  <div class="wheel" role="group" ref="root" v-bind="$attrs">    <template v-for="(column, at) in columns" :key="column.label">      <div class="wheel-column" role="listbox" :aria-label="column.label" tabindex="0">        <div v-for="option in column.options.map(row)" :key="option.value" class="wheel-option" role="option" :data-value="option.value" :aria-selected="option.value === first[at]" :aria-disabled="option.disabled || undefined">{{ option.label }}</div>      </div>      <span v-if="column.separator !== undefined" class="wheel-separator" aria-hidden="true">{{ column.separator }}</span>    </template>  </div></template>

#クラス

クラス説明
wheelホイールのくぼみと、その中央を横切る各列共通の目印
wheel-sm高さ32pxの行が3行。既定は高さ36pxの行が5行wheel と併用します
wheel-columnスクロール可能な列です。最初と最後を含むすべての選択肢が列の中央にスナップします。列の要素にはラベル、role="listbox"、tabindex="0" を指定します。
wheel-option列内の1つの値を表す要素。role="option" を指定します。
wheel-separator列の間で目印の位置に固定するテキスト。時刻のコロンや数値に続く単位などです。

#カスタムプロパティ

プロパティ既定値説明
--wheel-row2.25rem行と目印の高さです。
--wheel-rows5表示する行数。奇数にする
--wheel-radiusvar(--radius-control-lg)ホイールのくぼみの角の丸み

#ソース

@master/ui/components/wheel.css
/* * Wheel: a value picked by turning a column until it rests under a mark: an hour, a minute, a unit. * The wheel is a well. Each column in it is a scroll container that snaps one option to its center, and one * small sheet lies across the middle of the well, under the options, to say which row is the value; several * columns share it, as the hours and the minutes of one time do. A column fades into the well at both ends. * Scrolling and snapping are the platform's; the behavior moves a focused column by one option with the arrow * keys, by a page with Page Up and Page Down, and to its ends with Home and End. Where the browser has view timelines, each * option reads its own place in the column: it is full ink under the mark, and quieter and slightly turned * away the further it has gone. Elsewhere, and for assistive technology, the chosen option is the one a * script marks aria-selected, which it reads from how far the column has scrolled. */@layer components.ui {  .wheel {    --wheel-row: 2.25rem;    --wheel-rows: 5;    --wheel-radius: var(--radius-control-lg);    --wheel-inset: 4px;    position: relative;    display: inline-flex;    align-items: stretch;    justify-content: center;    max-width: 100%;    height: calc(var(--wheel-row) * var(--wheel-rows));    padding: 0 var(--wheel-inset);    border-radius: calc(var(--wheel-radius) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: var(--color-surface-inset);    color: var(--color-text-strong);    box-shadow: var(--shadow-pressed);    font: var(--font-weight-control) .9375rem/1 var(--font-family-sans);    font-feature-settings: inherit;    font-variant-numeric: tabular-nums;    vertical-align: middle;    isolation: isolate;    /* The script listens on the whole wheel for a tap on an option: it must not flash the wheel grey on iOS. */    -webkit-tap-highlight-color: transparent;    /* The mark: a sheet as tall as a row, 4px inside the well, with the concentric corner. */    &::before {      content: '';      position: absolute;      inset: calc(50% - var(--wheel-row) / 2) var(--wheel-inset) auto;      z-index: -1;      height: var(--wheel-row);      border-radius: calc(var(--wheel-radius) * var(--corner-scale) - var(--wheel-inset));      corner-shape: var(--corner-shape);      @apply --surface-sheet;      box-shadow: var(--shadow-raised);      pointer-events: none;    }    &.wheel-sm {      --wheel-row: 2rem;      --wheel-rows: 3;      --wheel-radius: var(--radius-control);      font-size: .875rem;    }    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;      &::before {        outline: 1px solid Highlight;        outline-offset: -1px;      }    }  }  /*   * A column: a listbox that scrolls. Start padding and an end spacer leave room for the first and last   * options to rest under the mark. The spacer participates in scrollable overflow even when a browser   * excludes trailing padding from a perspective container's scroll extent.   */  .wheel-column {    display: block;    flex: 1 1 auto;    min-width: 3.25rem;    margin: 0;    padding: calc((var(--wheel-rows) - 1) / 2 * var(--wheel-row)) 0 0;    overflow: hidden auto;    overscroll-behavior: contain;    list-style: none;    scroll-snap-type: y mandatory;    scrollbar-width: none;    mask-image: linear-gradient(to bottom, transparent, black 38%, black 62%, transparent);    perspective: 20rem;    &::after {      content: '';      display: block;      height: calc((var(--wheel-rows) - 1) / 2 * var(--wheel-row));    }    @media (forced-colors: active) {      mask-image: none;    }    /*     * Focused, the column's fade would cut its own ring at both ends. The mask keeps the fade and lets through     * a 2px frame around the box, where the ring is drawn inside it, so the whole ring shows on the column the     * keys are on.     */    &:focus-visible {      outline: 2px solid var(--color-focus);      outline-offset: -2px;      border-radius: calc(var(--wheel-radius) * var(--corner-scale) - var(--wheel-inset));      corner-shape: var(--corner-shape);      mask-image:        linear-gradient(to bottom, transparent, black 38%, black 62%, transparent),        linear-gradient(black, black), linear-gradient(black, black), linear-gradient(black, black), linear-gradient(black, black);      mask-position: 0 0, top, bottom, left, right;      mask-size: 100% 100%, 100% 2px, 100% 2px, 2px 100%, 2px 100%;      mask-repeat: no-repeat;      @media (forced-colors: active) {        mask-image: none;      }    }  }  .wheel-option {    display: flex;    align-items: center;    justify-content: center;    height: var(--wheel-row);    margin: 0;    padding: 0 .875rem;    color: var(--color-text-muted);    white-space: nowrap;    scroll-snap-align: center;    scroll-snap-stop: normal;    user-select: none;    -webkit-user-select: none;    &[aria-selected="true"] {      color: var(--color-text-strong);    }    /* Where supported, the first render starts on the selection. The behavior aligns it elsewhere. */    @supports (scroll-initial-target: nearest) {      &[aria-selected="true"]:not([aria-disabled="true"], [hidden]) {        scroll-initial-target: nearest;      }    }    &[aria-disabled="true"] {      color: var(--color-text-disabled);      /* Forced colors would give it the page's text color back: it keeps the system's disabled ink. */      @media (forced-colors: active) {        color: GrayText;      }    }    /*     * Each option is its own view timeline over the column. At the middle of its pass it is under the mark;     * a row away it has already let go of the ink.     */    @supports (animation-timeline: view()) {      &:not([aria-disabled="true"]) {        color: var(--color-text-strong);        animation-name: wheel-turn;        animation-timing-function: linear;        animation-fill-mode: both;        animation-timeline: view(block);        animation-range: cover;      }      @media (prefers-reduced-motion: reduce) {        &:not([aria-disabled="true"]) {          animation-name: wheel-fade;        }      }      /* In forced colors a faded value could not be read: every option is plain text, the chosen one marked by the sheet. */      @media (forced-colors: active) {        &:not([aria-disabled="true"]) {          animation-name: none;        }      }    }  }  /* Fixed text between columns: the colon of a time, a unit after a number. It rests on the mark. */  .wheel-separator {    display: flex;    flex: none;    align-items: center;    align-self: center;    height: var(--wheel-row);    color: var(--color-text-muted);    user-select: none;    -webkit-user-select: none;  }}@keyframes wheel-turn {  0% {    opacity: .2;    rotate: x -52deg;    scale: .86;  }  38% {    opacity: .42;    rotate: x -18deg;    scale: .96;  }  50% {    opacity: 1;    rotate: x 0deg;    scale: 1;  }  62% {    opacity: .42;    rotate: x 18deg;    scale: .96;  }  100% {    opacity: .2;    rotate: x 52deg;    scale: .86;  }}@keyframes wheel-fade {  0%, 100% {    opacity: .2;  }  38%, 62% {    opacity: .42;  }  50% {    opacity: 1;  }}