탐색

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를 적용합니다. 열은 두 값 사이에서 멈추지 않습니다. 양 끝에 여백을 두어 첫 번째와 마지막 옵션도 표시선에 닿을 수 있게 합니다.
  • 휠의 시각 효과는 스크롤 기반 애니메이션으로 구현합니다. 각 옵션에는 열을 기준으로 하는 자체 뷰 타임라인이 있습니다. 옵션이 중앙을 지날 때 가장 선명하며, 중앙에서 멀어질수록 흐려지고 살짝 돌아갑니다. 이 효과를 그리기 위해 스크립트로 스크롤 위치를 읽을 필요가 없습니다.

브라우저가 뷰 타임라인을 지원하지 않으면 모든 옵션이 회전 없이 표시되며, 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에는 옵션 요소가 들어 있습니다.
  • 초기 위치 설정. 동작이 연결될 때와 팝오버가 열리는 경우처럼 열의 레이아웃이 다시 계산될 때, 각 열에서 선택된 옵션을 표시선에 맞춥니다.
  • 옵션을 클릭하면 해당 옵션이 표시선으로 이동합니다.
  • 키 조작. 포커스된 열에서는 목록 상자와 같은 키를 사용해 옵션 단위로 이동합니다.
  • 비활성 옵션. 열이 aria-disabled="true"로 표시된 옵션에서 멈추면 가장 가까운 활성 옵션으로 이동합니다.

값을 폼과 함께 제출하려면 change 리스너에서 detail.value를 숨겨진 입력 필드에 복사합니다. 동작 없이도 열을 스크롤하고 스냅할 수 있습니다. scroll-initial-target을 지원하면 선택된 항목에서 시작하고, 그 외에는 첫 항목에서 시작합니다. aria-selected는 마크업에 설정된 상태로 유지됩니다.

#단일 열

휠에 열을 하나만 둘 수도 있습니다. 팝오버 안이나 설정 행에 휠을 배치할 때 wheel-sm을 사용하면 다섯 행 대신 세 행을 표시합니다.

단일 열

<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는 두 열 사이의 표시판 위에 놓이는 고정 텍스트로, 시와 분 사이의 콜론이나 숫자 뒤의 단위에 사용합니다.

행 높이는 포인터 종류와 관계없이 36px입니다. 한 열에서 더 많은 행을 표시하려면 --wheel-rows를 홀수로 설정합니다.

#다른 컴포넌트가 적합한 경우

휠은 터치 기기에서 값이 적고 순서가 정해져 있으며 사용자가 그 값들에 익숙할 때 적합합니다. 키보드와 포인터를 사용할 때는 셀렉트나 스테퍼가 더 빠르며, 날짜를 고를 때는 캘린더에서 선택하려는 날짜가 속한 주를 볼 수 있습니다. 휴대폰에서 네이티브 <input type="time">을 사용하면 플랫폼의 기본 휠이 열립니다. 선택기를 페이지 안에 배치해야 할 때는 이 휠을 사용하세요.

#키보드

동작을 연결하면 포커스가 있는 열에서 키를 눌러 옵션을 하나씩 이동하며 비활성 옵션은 건너뜁니다. 동작을 연결하지 않으면 같은 키로 다른 스크롤 컨테이너에서처럼 열을 스크롤하고, 스냅으로 최종 위치를 맞춥니다.

키동작
ArrowUp, ArrowDown포커스가 있는 열을 스크롤해 이전 또는 다음 옵션이 표시선 아래에 오도록 합니다. 비활성화된 옵션은 건너뜁니다.
PageUp, PageDown포커스가 있는 열을 현재 보이는 옵션 수만큼 한 페이지 스크롤합니다.
Home, End포커스가 있는 열을 첫 번째 또는 마지막 옵션까지 스크롤합니다.

#접근성

  • 각 열은 role="listbox"이며 aria-label과 tabindex="0"을 지정합니다. 각 옵션은 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-sm32px 높이의 행 3개를 표시합니다. 기본값은 36px 높이의 행 5개입니다.적용할 클래스는 wheel입니다
wheel-column스크롤하면 첫 번째와 마지막 옵션을 포함한 모든 옵션이 중앙에 맞춰지는 열입니다. role="listbox"를 지정한 요소에 레이블과 tabindex="0"을 지정하세요.
wheel-option열의 값 하나를 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;  }}