網站導覽

v2.1.0
表單

旋鈕

沿著圓周轉動滑塊來設定數值,例如以旋鈕方式調整的程度、角度或方向。

本頁內容

旋鈕是沿著圓周轉動滑塊來設定數值的控制項,可用來設定像轉鈕那樣調整的強度、角度或方向。它是儀表的輸入版:圓形軌道採用與填色相同的色調,底色較淡,從起點到目前值的區段則以較濃的同色填滿。滑桿的珠狀滑塊位於目前值對應的角度。數字以等寬數字顯示在中央。平台沒有對應的原生元素,因此旋鈕是帶有 role="slider" 的元素,由 dial 行為負責轉動。

旋鈕

<div class="dial" role="slider" tabindex="0" aria-label="Volume" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="--dial-value: 40">  <span class="dial-value">40%</span>  <span class="dial-thumb"></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} className="dial" role="slider" tabIndex={0} aria-label="Volume" aria-valuenow={40} aria-valuemin={0} aria-valuemax={100} style={{ '--dial-value': '40' } as React.CSSProperties}>      <span className="dial-value">40%</span>      <span className="dial-thumb"></span>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'</script><div class="dial" role="slider" tabindex="0" aria-label="Volume" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="--dial-value: 40" {@attach attach}>  <span class="dial-value">40%</span>  <span class="dial-thumb"></span></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="dial" role="slider" tabindex="0" aria-label="Volume" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="--dial-value: 40">    <span class="dial-value">40%</span>    <span class="dial-thumb"></span>  </div></template>
沿圓周拖曳滑塊、在軌道上任一處按下,或讓旋鈕取得焦點後使用方向鍵、Page Up、Page Down、Home 和 End。

旋鈕預設為轉鈕形式:涵蓋 270 度,底部留有缺口,最小值在左下方,最大值在右下方。在軌道上按下時,值會移到該處;按住滑塊時,則會從它目前的位置抓住它,轉動時不會跳動。拖曳超過端點時,值會停在該端點,即使指標經過底部的缺口也一樣,直到指標回到範圍內為止。

#角度

dial-full 涵蓋整個圓,從頂端開始,用來設定角度或方向,範圍從 aria-valuemin 的 0 到 aria-valuemax 的 360。無論是按鍵操作還是拖曳經過頂端,超過最大值後都會繞回最小值,而 360 會寫成 0,因為兩者是同一個位置。End 會停在 360 的前一個步距。

角度

<div class="dial dial-full" role="slider" tabindex="0" aria-label="Gradient angle" aria-valuenow="135" aria-valuemin="0" aria-valuemax="360" aria-valuetext="135°" style="--dial-value: 135; --dial-max: 360">  <span class="dial-value">135°</span>  <span class="dial-thumb"></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} className="dial dial-full" role="slider" tabIndex={0} aria-label="Gradient angle" aria-valuenow={135} aria-valuemin={0} aria-valuemax={360} aria-valuetext="135°" style={{ '--dial-value': '135', '--dial-max': '360' } as React.CSSProperties}>      <span className="dial-value">135°</span>      <span className="dial-thumb"></span>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'</script><div class="dial dial-full" role="slider" tabindex="0" aria-label="Gradient angle" aria-valuenow="135" aria-valuemin="0" aria-valuemax="360" aria-valuetext="135°" style="--dial-value: 135; --dial-max: 360" {@attach attach}>  <span class="dial-value">135°</span>  <span class="dial-thumb"></span></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="dial dial-full" role="slider" tabindex="0" aria-label="Gradient angle" aria-valuenow="135" aria-valuemin="0" aria-valuemax="360" aria-valuetext="135°" style="--dial-value: 135; --dial-max: 360">    <span class="dial-value">135°</span>    <span class="dial-thumb"></span>  </div></template>
將它轉過頂端,或在 359 時按向上鍵。

標籤和 aria-valuetext 會保留數字前後原本寫好的文字,因此不需要頁面的任何腳本,「135°」就會變成「136°」。若需要其他形式的文字,請傳入 text 函式給行為,用法如行為所示。

#刻度與標記

dial-ticks 元素會在滑塊路徑外側,以細線將掃過的範圍畫成 --dial-ticks 個等分:轉鈕的刻度比等分數多一條,兩端各一條;整圓的刻度則與等分數相同。dial-mark 是外緣上的簡短文字或數字,樣式表會將它放在其 --dial-at 所代表的數值位置。兩者都會在旋鈕的方框內占用一圈外緣,因此軌道會縮小以容納它們;有標記的旋鈕請使用大尺寸。

刻度與標記

<div class="dial dial-lg" role="slider" tabindex="0" aria-label="Volume" aria-valuenow="6" aria-valuemin="0" aria-valuemax="10" style="--dial-value: 6; --dial-max: 10">  <span class="dial-ticks" style="--dial-ticks: 10"></span>  <span class="dial-mark" style="--dial-at: 0">0</span>  <span class="dial-mark" style="--dial-at: 5">5</span>  <span class="dial-mark" style="--dial-at: 10">10</span>  <span class="dial-value">6</span>  <span class="dial-thumb"></span></div><div class="dial dial-lg dial-full" role="slider" tabindex="0" aria-label="Wind direction" aria-valuenow="225" aria-valuemin="0" aria-valuemax="360" aria-valuetext="225°" style="--dial-value: 225; --dial-max: 360">  <span class="dial-ticks" style="--dial-ticks: 12"></span>  <span class="dial-mark" style="--dial-at: 0">N</span>  <span class="dial-mark" style="--dial-at: 90">E</span>  <span class="dial-mark" style="--dial-at: 180">S</span>  <span class="dial-mark" style="--dial-at: 270">W</span>  <span class="dial-value">225°</span>  <span class="dial-thumb"></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="dial dial-lg" role="slider" tabIndex={0} aria-label="Volume" aria-valuenow={6} aria-valuemin={0} aria-valuemax={10} style={{ '--dial-value': '6', '--dial-max': '10' } as React.CSSProperties}>        <span className="dial-ticks" style={{ '--dial-ticks': '10' } as React.CSSProperties}></span>        <span className="dial-mark" style={{ '--dial-at': '0' } as React.CSSProperties}>0</span>        <span className="dial-mark" style={{ '--dial-at': '5' } as React.CSSProperties}>5</span>        <span className="dial-mark" style={{ '--dial-at': '10' } as React.CSSProperties}>10</span>        <span className="dial-value">6</span>        <span className="dial-thumb"></span>      </div>      <div className="dial dial-lg dial-full" role="slider" tabIndex={0} aria-label="Wind direction" aria-valuenow={225} aria-valuemin={0} aria-valuemax={360} aria-valuetext="225°" style={{ '--dial-value': '225', '--dial-max': '360' } as React.CSSProperties}>        <span className="dial-ticks" style={{ '--dial-ticks': '12' } as React.CSSProperties}></span>        <span className="dial-mark" style={{ '--dial-at': '0' } as React.CSSProperties}>N</span>        <span className="dial-mark" style={{ '--dial-at': '90' } as React.CSSProperties}>E</span>        <span className="dial-mark" style={{ '--dial-at': '180' } as React.CSSProperties}>S</span>        <span className="dial-mark" style={{ '--dial-at': '270' } as React.CSSProperties}>W</span>        <span className="dial-value">225°</span>        <span className="dial-thumb"></span>      </div>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'</script><div {@attach attach}>  <div class="dial dial-lg" role="slider" tabindex="0" aria-label="Volume" aria-valuenow="6" aria-valuemin="0" aria-valuemax="10" style="--dial-value: 6; --dial-max: 10">    <span class="dial-ticks" style="--dial-ticks: 10"></span>    <span class="dial-mark" style="--dial-at: 0">0</span>    <span class="dial-mark" style="--dial-at: 5">5</span>    <span class="dial-mark" style="--dial-at: 10">10</span>    <span class="dial-value">6</span>    <span class="dial-thumb"></span>  </div>  <div class="dial dial-lg dial-full" role="slider" tabindex="0" aria-label="Wind direction" aria-valuenow="225" aria-valuemin="0" aria-valuemax="360" aria-valuetext="225°" style="--dial-value: 225; --dial-max: 360">    <span class="dial-ticks" style="--dial-ticks: 12"></span>    <span class="dial-mark" style="--dial-at: 0">N</span>    <span class="dial-mark" style="--dial-at: 90">E</span>    <span class="dial-mark" style="--dial-at: 180">S</span>    <span class="dial-mark" style="--dial-at: 270">W</span>    <span class="dial-value">225°</span>    <span class="dial-thumb"></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="dial dial-lg" role="slider" tabindex="0" aria-label="Volume" aria-valuenow="6" aria-valuemin="0" aria-valuemax="10" style="--dial-value: 6; --dial-max: 10">      <span class="dial-ticks" style="--dial-ticks: 10"></span>      <span class="dial-mark" style="--dial-at: 0">0</span>      <span class="dial-mark" style="--dial-at: 5">5</span>      <span class="dial-mark" style="--dial-at: 10">10</span>      <span class="dial-value">6</span>      <span class="dial-thumb"></span>    </div>    <div class="dial dial-lg dial-full" role="slider" tabindex="0" aria-label="Wind direction" aria-valuenow="225" aria-valuemin="0" aria-valuemax="360" aria-valuetext="225°" style="--dial-value: 225; --dial-max: 360">      <span class="dial-ticks" style="--dial-ticks: 12"></span>      <span class="dial-mark" style="--dial-at: 0">N</span>      <span class="dial-mark" style="--dial-at: 90">E</span>      <span class="dial-mark" style="--dial-at: 180">S</span>      <span class="dial-mark" style="--dial-at: 270">W</span>      <span class="dial-value">225°</span>      <span class="dial-thumb"></span>    </div>  </div></template>

刻度和標記只是圖形:在 role="slider" 內不會被朗讀,因此標記所表達的一切,都必須由值和它的文字說明。

#尺寸

旋鈕的直徑為 120px。dial-sm 為 88px,適合排成一列的控制項;dial-lg 為 160px,適合作為面板主角的單一數值,或帶有標記的旋鈕。軌道寬度為直徑的二十分之一,數字會隨軌道縮放;無論使用哪種指標裝置,滑塊都維持與滑桿相同的 18px。

尺寸

<div class="dial dial-sm" role="slider" tabindex="0" aria-label="Treble" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" style="--dial-value: 30">  <span class="dial-value">30</span>  <span class="dial-thumb"></span></div><div class="dial" role="slider" tabindex="0" aria-label="Mid" aria-valuenow="55" aria-valuemin="0" aria-valuemax="100" style="--dial-value: 55">  <span class="dial-value">55</span>  <span class="dial-thumb"></span></div><div class="dial dial-lg" role="slider" tabindex="0" aria-label="Bass" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="--dial-value: 70">  <span class="dial-value">70</span>  <span class="dial-thumb"></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="dial dial-sm" role="slider" tabIndex={0} aria-label="Treble" aria-valuenow={30} aria-valuemin={0} aria-valuemax={100} style={{ '--dial-value': '30' } as React.CSSProperties}>        <span className="dial-value">30</span>        <span className="dial-thumb"></span>      </div>      <div className="dial" role="slider" tabIndex={0} aria-label="Mid" aria-valuenow={55} aria-valuemin={0} aria-valuemax={100} style={{ '--dial-value': '55' } as React.CSSProperties}>        <span className="dial-value">55</span>        <span className="dial-thumb"></span>      </div>      <div className="dial dial-lg" role="slider" tabIndex={0} aria-label="Bass" aria-valuenow={70} aria-valuemin={0} aria-valuemax={100} style={{ '--dial-value': '70' } as React.CSSProperties}>        <span className="dial-value">70</span>        <span className="dial-thumb"></span>      </div>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'</script><div {@attach attach}>  <div class="dial dial-sm" role="slider" tabindex="0" aria-label="Treble" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" style="--dial-value: 30">    <span class="dial-value">30</span>    <span class="dial-thumb"></span>  </div>  <div class="dial" role="slider" tabindex="0" aria-label="Mid" aria-valuenow="55" aria-valuemin="0" aria-valuemax="100" style="--dial-value: 55">    <span class="dial-value">55</span>    <span class="dial-thumb"></span>  </div>  <div class="dial dial-lg" role="slider" tabindex="0" aria-label="Bass" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="--dial-value: 70">    <span class="dial-value">70</span>    <span class="dial-thumb"></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="dial dial-sm" role="slider" tabindex="0" aria-label="Treble" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" style="--dial-value: 30">      <span class="dial-value">30</span>      <span class="dial-thumb"></span>    </div>    <div class="dial" role="slider" tabindex="0" aria-label="Mid" aria-valuenow="55" aria-valuemin="0" aria-valuemax="100" style="--dial-value: 55">      <span class="dial-value">55</span>      <span class="dial-thumb"></span>    </div>    <div class="dial dial-lg" role="slider" tabindex="0" aria-label="Bass" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="--dial-value: 70">      <span class="dial-value">70</span>      <span class="dial-thumb"></span>    </div>  </div></template>

#在表單中

role="slider" 不是表單控制項,因此旋鈕內含一個隱藏輸入元件。每次變更時,行為都會將值寫入旋鈕內第一個 <input type="hidden">,表單會以該輸入元件的 name 送出這個值。旋鈕的 input 和 change 事件會像原生控制項一樣冒泡到表單。表單重設不會影響隱藏輸入元件,因此旋鈕會停在原處;若重設時旋鈕也要跟著改變,請由頁面重新設定它的值。

在表單中

<form class="flex flex-col items-center gap-sm">  <span class="text-sm fg-text-strong" id="heating-label">Heating</span>  <div class="dial" role="slider" tabindex="0" aria-labelledby="heating-label" aria-valuenow="21" aria-valuemin="16" aria-valuemax="30" style="--dial-value: 21; --dial-min: 16; --dial-max: 30">    <span class="dial-value">21°</span>    <span class="dial-thumb"></span>    <input type="hidden" name="temperature" value="21">  </div>  <span class="text-xs fg-text-muted">16° to 30°</span></form><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<HTMLFormElement>(null)  useEffect(() => attach(root.current!), [])  return (    <form ref={root} className="flex flex-col items-center gap-sm">      <span className="text-sm fg-text-strong" id="heating-label">Heating</span>      <div className="dial" role="slider" tabIndex={0} aria-labelledby="heating-label" aria-valuenow={21} aria-valuemin={16} aria-valuemax={30} style={{ '--dial-value': '21', '--dial-min': '16', '--dial-max': '30' } as React.CSSProperties}>        <span className="dial-value">21°</span>        <span className="dial-thumb"></span>        <input type="hidden" name="temperature" value="21" />      </div>      <span className="text-xs fg-text-muted">16° to 30°</span>    </form>  )}
<script>  import { attach } from '@master/ui/behaviors'</script><form class="flex flex-col items-center gap-sm" {@attach attach}>  <span class="text-sm fg-text-strong" id="heating-label">Heating</span>  <div class="dial" role="slider" tabindex="0" aria-labelledby="heating-label" aria-valuenow="21" aria-valuemin="16" aria-valuemax="30" style="--dial-value: 21; --dial-min: 16; --dial-max: 30">    <span class="dial-value">21°</span>    <span class="dial-thumb"></span>    <input type="hidden" name="temperature" value="21">  </div>  <span class="text-xs fg-text-muted">16° to 30°</span></form>
<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>  <form ref="root" class="flex flex-col items-center gap-sm">    <span class="text-sm fg-text-strong" id="heating-label">Heating</span>    <div class="dial" role="slider" tabindex="0" aria-labelledby="heating-label" aria-valuenow="21" aria-valuemin="16" aria-valuemax="30" style="--dial-value: 21; --dial-min: 16; --dial-max: 30">      <span class="dial-value">21°</span>      <span class="dial-thumb"></span>      <input type="hidden" name="temperature" value="21">    </div>    <span class="text-xs fg-text-muted">16° to 30°</span>  </form></template>

可見的標籤是獨立的元素,以 aria-labelledby 指向它:<label> 只能為表單控制項命名。若從數字無法清楚看出範圍,請在旋鈕旁以文字標示。

#停用

aria-disabled="true" 會讓旋鈕淡化,並使它不回應任何按鍵、指標和滾輪操作。請用 tabindex="-1" 將它移出 Tab 鍵的巡覽順序,並在它的隱藏輸入元件上也加上 disabled,讓表單不送出這個值。

停用

<div class="dial" role="slider" tabindex="-1" aria-label="Volume" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" aria-disabled="true" style="--dial-value: 40">  <span class="dial-value">40%</span>  <span class="dial-thumb"></span>  <input type="hidden" name="volume" value="40" disabled></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="dial" role="slider" tabIndex={-1} aria-label="Volume" aria-valuenow={40} aria-valuemin={0} aria-valuemax={100} aria-disabled="true" style={{ '--dial-value': '40' } as React.CSSProperties}>      <span className="dial-value">40%</span>      <span className="dial-thumb"></span>      <input type="hidden" name="volume" value="40" disabled />    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'</script><div class="dial" role="slider" tabindex="-1" aria-label="Volume" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" aria-disabled="true" style="--dial-value: 40" {@attach attach}>  <span class="dial-value">40%</span>  <span class="dial-thumb"></span>  <input type="hidden" name="volume" value="40" disabled></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="dial" role="slider" tabindex="-1" aria-label="Volume" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" aria-disabled="true" style="--dial-value: 40">    <span class="dial-value">40%</span>    <span class="dial-thumb"></span>    <input type="hidden" name="volume" value="40" disabled>  </div></template>

#轉動方向

無論書寫方向為何,順時針都代表增加。旋鈕的轉法和時鐘或裝置上的轉鈕一樣,而這些東西在從右到左的版面中不會左右翻轉,因此旋鈕也不會,方向鍵的方向也不會對調:→ 和 ↑ 一律增加數值。在視線起始的旋鈕頂端,順時針就是往右;這也是在該處讓它增加的方向鍵。

#行為

dial 接收根元素,也就是帶有 dial 類別的元素,並傳回用來解除行為的函式。這個函式有一個 value,也就是數值:從外部設定它即可轉動旋鈕,這樣做不會觸發任何事件。

app.js
import { dial } from '@master/ui/behaviors/dial.js'const root = document.querySelector('.dial')const turn = dial(root, { step: 15, text: (value) => `${value}°` })root.addEventListener('change', () => save(turn.value))
  • 每次變更都會將值寫入根元素的 aria-valuenow 和 --dial-value、dial-value 的文字、aria-valuetext(若已存在或有提供 text),以及隱藏輸入元件。掛上行為時,會以相同方式寫入初始值,並將 aria-valuemin 和 aria-valuemax 複製到 --dial-min 和 --dial-max,供無法讀取屬性的瀏覽器使用。
  • 值會落在從 aria-valuemin 起算的步距上,介於它和 aria-valuemax 之間,省略時分別為 0 和 100;整圓的旋鈕則會繞回。
  • 拖曳。 pointerdown 時,行為會擷取指標並讀取它繞旋鈕中心的角度,再用樣式表繪製時所用的同一組 --dial-start 和 --dial-sweep 將角度換算為數值。掃過範圍為 360 度的旋鈕都會繞回,不論是否帶有 dial-full。在中央附近、也就是數字上按下時,不會改變數值。
  • 按鍵。 方向鍵每次轉動一個步距,Page Up 和 Page Down 轉動較大的幅度,Home 和 End 則移到兩端。
  • 滾輪在有要求時才會啟用,每一格轉動一個步距,但只有在按住 Alt(Option)時才有作用:捲動頁面經過旋鈕時,絕不會轉動它。
  • 事件。 值每次變動時,根元素都會觸發 input;拖曳結束,或以按鍵或滾輪轉動後,則觸發 change。兩者都會冒泡。
  • 停用。 帶有 aria-disabled="true" 的旋鈕不回應按鍵、指標或滾輪。
選項設定內容
step方向鍵每次轉動數值的幅度,也是拖曳時取整的單位。預設為 1
pagePage Up 和 Page Down 轉動的幅度。預設為範圍的十分之一,並對齊步距
text將數值轉為文字的函式,結果會寫入 dial-value 和 aria-valuetext
wheel設為 true 時,按住 Alt 可用滾輪轉動旋鈕。預設為 false

attach() 不會傳入任何選項。需要選項的旋鈕要在 attach() 執行後另外掛上行為:在同一個根元素上再次呼叫會取代前一次,這個預覽的腳本就是這樣做的。MasterUI 是預覽載入的套件包;在專案中,請依上方所示匯入 dial。

步距、文字與滾輪

<div class="dial dial-full" id="hue" role="slider" tabindex="0" aria-label="Hue" aria-valuenow="210" aria-valuemin="0" aria-valuemax="360" style="--dial-value: 210; --dial-max: 360">  <span class="dial-ticks" style="--dial-ticks: 24"></span>  <span class="dial-value">210°</span>  <span class="dial-thumb"></span></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.dial(document.getElementById('hue'), {  step: 15,  wheel: true,  text: function (value) { return value + '°' }})})</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach, dial } from '@master/ui/behaviors'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => {    const detach = [      attach(root.current!),      dial(document.getElementById('hue')!, {        step: 15,        wheel: true,        text: function (value) { return value + '°' }      }),    ]    return () => detach.forEach(stop => stop())  }, [])  return (    <div ref={root} className="dial dial-full" id="hue" role="slider" tabIndex={0} aria-label="Hue" aria-valuenow={210} aria-valuemin={0} aria-valuemax={360} style={{ '--dial-value': '210', '--dial-max': '360' } as React.CSSProperties}>      <span className="dial-ticks" style={{ '--dial-ticks': '24' } as React.CSSProperties}></span>      <span className="dial-value">210°</span>      <span className="dial-thumb"></span>    </div>  )}
<script>  import { attach, dial } from '@master/ui/behaviors'  function mounted(root) {    const detach = [      attach(root),      dial(document.getElementById('hue'), {        step: 15,        wheel: true,        text: function (value) { return value + '°' }      }),    ]    return () => detach.forEach(stop => stop())  }</script><div class="dial dial-full" id="hue" role="slider" tabindex="0" aria-label="Hue" aria-valuenow="210" aria-valuemin="0" aria-valuemax="360" style="--dial-value: 210; --dial-max: 360" {@attach mounted}>  <span class="dial-ticks" style="--dial-ticks: 24"></span>  <span class="dial-value">210°</span>  <span class="dial-thumb"></span></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach, dial } from '@master/ui/behaviors'const root = ref(null)let detach = []onMounted(() => {  detach = [    attach(root.value),    dial(document.getElementById('hue'), {      step: 15,      wheel: true,      text: function (value) { return value + '°' }    }),  ]})onUnmounted(() => detach.forEach(stop => stop()))</script><template>  <div ref="root" class="dial dial-full" id="hue" role="slider" tabindex="0" aria-label="Hue" aria-valuenow="210" aria-valuemin="0" aria-valuemax="360" style="--dial-value: 210; --dial-max: 360">    <span class="dial-ticks" style="--dial-ticks: 24"></span>    <span class="dial-value">210°</span>    <span class="dial-thumb"></span>  </div></template>
每次按鍵和每一格滾輪都是 15 度。按住 Alt(Option)並在旋鈕上捲動即可轉動。

未掛上行為時,旋鈕會顯示初始值,在支援具型別 attr() 的瀏覽器中取自屬性,其他瀏覽器則取自 --dial-value,但無法轉動。

#鍵盤操作

按鍵動作
ArrowUp, ArrowRight將數值調高一步,在任何書寫方向都是順時針。整圈模式下,超過最大值會繞回最小值
ArrowDown, ArrowLeft將數值調低一步,逆時針轉動。整圈模式下,低於最小值會繞回最大值
PageUp, PageDown以較大的步幅調高或調低數值,預設為範圍的十分之一,頁面可另行設定
Home, End移到 aria-valuemin 或 aria-valuemax。整圈模式下,End 會移到數值繞回前的最後一步

#無障礙

  • 根元素是可取得焦點的 role="slider",具有來自 aria-label 或 aria-labelledby 的無障礙名稱,值寫在 aria-valuenow 中,介於 aria-valuemin 和 aria-valuemax 之間。滑桿的方向性在圓周上沒有意義,因此請省略 aria-orientation。
  • 若數字需要單位或文字才能理解,請寫入 aria-valuetext,例如「135°」、「21 degrees」、「Loud」。行為會讓它與值保持同步。
  • 旋鈕內的數字、刻度和標記都僅供視覺呈現,輔助技術不會逐一讀出。按鍵能完成拖曳所能做的一切,在軌道上按一下也能設定數值,因此拖曳轉動永遠不是唯一的操作方式。
  • 取得焦點時,滑塊會顯示焦點外框,與滑桿相同。在觸控螢幕上,整個旋鈕都會接收手指操作,轉動旋鈕而不是捲動頁面,因此滑塊維持原本的尺寸。
  • 啟用減少動態效果時,按住的滑塊不會放大。強制色彩模式下,填色使用系統醒目提示色,軌道和刻度使用系統的灰色,滑塊則使用按鈕文字顏色。

#React、Svelte 和 Vue

dial 元件會掛上行為,並支援傳入及傳出數值。它會根據資料算繪刻度和標記,提供 name 時也會算繪隱藏輸入元件。用 npx master-ui add dial 將元件複製到專案中。元件的建置與使用方式請參閱 React、Svelte 和 Vue。

ui/dial.tsx
'use client'import { useRef, useState, type ComponentProps, type CSSProperties } from 'react'import { dial } from '@master/ui/behaviors/dial.js'import { useBehavior } from './use-behavior'/** A word or figure in the rim, at a value. Without a label it shows the value. */export interface DialMark {  value: number  label?: string}export interface DialProps extends Omit<ComponentProps<'div'>, 'defaultValue' | 'children' | 'onChange' | 'role' | 'ref'> {  /** The number. */  value?: number  defaultValue?: number  /** Called as the dial turns. */  onValueChange?: (value: number) => void  /** Called once a drag ends, or a key or the wheel turned it. */  onValueCommit?: (value: number) => void  /** The least and the greatest value: 0 and 100, or 0 and 360 round a full circle. */  min?: number  max?: number  /** How far an arrow key turns the value, and what a drag rounds it to. */  step?: number  /** How far PageUp and PageDown turn it; a tenth of the range by default. */  page?: number  /** The whole circle, for an angle that comes round again. */  full?: boolean  /** The name of the dial: what it sets. */  label: string  /** The words for a value, shown in the middle and given to assistive technology. */  text?: (value: number) => string  /** The name a form submits the value under. Without it there is no field. */  name?: string  /** How many equal steps to mark with ticks. */  ticks?: number  /** Words or figures in the rim, at their values. */  marks?: DialMark[]  /** Let a wheel turn the dial while Alt (Option) is held. */  wheel?: boolean  disabled?: boolean}/** A value set by turning a thumb around a circle. */export function Dial({ value, defaultValue, onValueChange, onValueCommit, min = 0, max, step = 1, page, full, label, text, name, ticks, marks, wheel = false, disabled, className, style, ...root }: DialProps) {  const greatest = max ?? (full ? 360 : 100)  const [first] = useState(value ?? defaultValue ?? min)  /** The value the dial holds: what `text` is written for, since a `text` given later is not for the first value. */  const held = useRef(first)  const ref = useBehavior(dial, { step, page, text, wheel }, {    value,    defaultValue,    onValueChange: (next: number) => { held.current = next; onValueChange?.(next) },    // The dial says change once a drag ends or a key or the wheel turned it, after the value has come out.    on: { change: (event) => { if (event.target === event.currentTarget) onValueCommit?.(Number((event.currentTarget as Element).getAttribute('aria-valuenow'))) } },  })  return (    <div className={['dial', full && 'dial-full', className].filter(Boolean).join(' ')} role="slider" tabIndex={disabled ? -1 : 0} aria-label={label} aria-valuenow={first} aria-valuemin={min} aria-valuemax={greatest} aria-valuetext={text?.(value ?? held.current)} aria-disabled={disabled || undefined} style={{ '--dial-value': first, '--dial-min': min, '--dial-max': greatest, ...style } as CSSProperties} ref={ref} {...root}>      {ticks !== undefined && <span className="dial-ticks" style={{ '--dial-ticks': ticks } as CSSProperties} />}      {marks?.map(mark => <span className="dial-mark" key={mark.value} style={{ '--dial-at': mark.value } as CSSProperties}>{mark.label ?? String(mark.value)}</span>)}      <span className="dial-value">{text ? text(value ?? held.current) : String(value ?? held.current)}</span>      <span className="dial-thumb" />      {/* React writes a field's value with every render, so it writes the value the dial holds. */}      {name !== undefined && <input type="hidden" name={name} value={value ?? held.current} disabled={disabled} />}    </div>  )}
ui/Dial.svelte
<script lang="ts" module>  import type { HTMLAttributes } from 'svelte/elements'  /** A word or figure in the rim, at a value. Without a label it shows the value. */  export interface DialMark {    value: number    label?: string  }  export interface DialProps extends Omit<HTMLAttributes<HTMLDivElement>, 'role' | 'children'> {    /** The number. Bind it, or leave it out: it starts at `min`. */    value?: number    /** Called as the dial turns. */    onValueChange?: (value: number) => void    /** Called once a drag ends, or a key or the wheel turned it. */    onValueCommit?: (value: number) => void    /** The least and the greatest value: 0 and 100, or 0 and 360 round a full circle. */    min?: number    max?: number    /** How far an arrow key turns the value, and what a drag rounds it to. */    step?: number    /** How far PageUp and PageDown turn it; a tenth of the range by default. */    page?: number    /** The whole circle, for an angle that comes round again. */    full?: boolean    /** The name of the dial: what it sets. */    label: string    /** The words for a value, shown in the middle and given to assistive technology. */    text?: (value: number) => string    /** The name a form submits the value under. Without it there is no field. */    name?: string    /** How many equal steps to mark with ticks. */    ticks?: number    /** Words or figures in the rim, at their values. */    marks?: DialMark[]    /** Let a wheel turn the dial while Alt (Option) is held. */    wheel?: boolean    disabled?: boolean  }</script><script lang="ts">  import { untrack } from 'svelte'  import { dial } from '@master/ui/behaviors/dial.js'  import { behavior } from './behavior.svelte.js'  let { value = $bindable(), onValueChange, onValueCommit, min = 0, max, step = 1, page, full, label, text, name, ticks, marks, wheel = false, disabled, class: className, ...root }: DialProps = $props()  const greatest = $derived(max ?? (full ? 360 : 100))  const first = untrack(() => value ?? min)  // Svelte writes a style again whenever its owner changes it, so it writes the value the behavior holds.  let held = $state(first)  // The behavior writes the words over the ones Svelte rendered, so words given another way are written by it:  // it attaches again, from the value it holds, each time `text` is another function.  let written = 0  const words = $derived.by(() => {    // Reading `text` is what makes this run again when it is another function.    void text    return ++written  })  const told = (root: HTMLElement, options?: { step?: number, page?: number, text?: (value: number) => string, wheel?: boolean, words?: number }) => dial(root, { step: options?.step, page: options?.page, text: options?.text, wheel: options?.wheel })  const attach = behavior(told, () => ({ step, page, text, wheel, words }), {    value: () => value,    change: (next) => { value = held = next; onValueChange?.(next) },    settled: (next) => { held = next },    // The dial says change once a drag ends or a key or the wheel turned it, after the value has come out.    on: { change: (event) => { if (event.target === event.currentTarget) onValueCommit?.(held) } },  })</script><!--  @component  A value set by turning a thumb around a circle.--><div class={['dial', full && 'dial-full', className]} role="slider" tabindex={disabled ? -1 : 0} aria-label={label} aria-valuenow={first} aria-valuemin={min} aria-valuemax={greatest} aria-valuetext={text?.(held)} aria-disabled={disabled || undefined} style:--dial-value={held} style:--dial-min={min} style:--dial-max={greatest} {@attach attach} {...root}>  {#if ticks !== undefined}<span class="dial-ticks" style:--dial-ticks={ticks}></span>{/if}  {#each marks ?? [] as mark (mark.value)}    <span class="dial-mark" style:--dial-at={mark.value}>{mark.label ?? String(mark.value)}</span>  {/each}  <span class="dial-value">{text ? text(held) : String(held)}</span>  <span class="dial-thumb"></span>  {#if name !== undefined}<input type="hidden" {name} value={first} {disabled} />{/if}</div>
ui/Dial.vue
<script lang="ts">/** A word or figure in the rim, at a value. Without a label it shows the value. */export interface DialMark {  value: number  label?: string}</script><script setup lang="ts">import { computed, useTemplateRef } from 'vue'import { dial } from '@master/ui/behaviors/dial.js'import { useBehavior } from './use-behavior'defineOptions({ inheritAttrs: false })const { min = 0, max, step = 1, page, full, text, wheel = false } = defineProps<{  /** The least and the greatest value: 0 and 100, or 0 and 360 round a full circle. */  min?: number  max?: number  /** How far an arrow key turns the value, and what a drag rounds it to. */  step?: number  /** How far PageUp and PageDown turn it; a tenth of the range by default. */  page?: number  /** The whole circle, for an angle that comes round again. */  full?: boolean  /** The name of the dial: what it sets. */  label: string  /** The words for a value, shown in the middle and given to assistive technology. */  text?: (value: number) => string  /** The name a form submits the value under. Without it there is no field. */  name?: string  /** How many equal steps to mark with ticks. */  ticks?: number  /** Words or figures in the rim, at their values. */  marks?: DialMark[]  /** Let a wheel turn the dial while Alt (Option) is held. */  wheel?: boolean  disabled?: boolean}>()/** The number: `v-model`. It changes as the dial turns. */const model = defineModel<number>()const emit = defineEmits<{  /** The number, once a drag ends, or a key or the wheel turned it. */  valueCommit: [value: number]}>()/* A value set by turning a thumb around a circle. */const greatest = computed(() => max ?? (full ? 360 : 100))const first = model.value ?? minconst root = useTemplateRef<HTMLDivElement>('root')const current = useBehavior(root, dial, () => ({ step, page, text, wheel }), model, {  // The dial says change once a drag ends or a key or the wheel turned it, after the model has heard it.  change: (event) => { if (event.target === root.value) emit('valueCommit', held()) },})// Vue writes a style again each time it renders, so it writes the value the behavior holds, not the first one.const held = () => current() ?? first</script><template>  <div class="dial" :class="{ 'dial-full': full }" role="slider" ref="root" :tabindex="disabled ? -1 : 0" :aria-label="label" :aria-valuenow="first" :aria-valuemin="min" :aria-valuemax="greatest" :aria-valuetext="text?.(held())" :aria-disabled="disabled || undefined" :style="{ '--dial-value': held(), '--dial-min': min, '--dial-max': greatest }" v-bind="$attrs">    <span v-if="ticks !== undefined" class="dial-ticks" :style="{ '--dial-ticks': ticks }" />    <span v-for="mark in marks" :key="mark.value" class="dial-mark" :style="{ '--dial-at': mark.value }">{{ mark.label ?? String(mark.value) }}</span>    <span class="dial-value">{{ text ? text(held()) : String(held()) }}</span>    <span class="dial-thumb" />    <!-- Vue writes a field's value with every render, so it too is the value the behavior holds. -->    <input v-if="name !== undefined" type="hidden" :name="name" :value="held()" :disabled="disabled">  </div></template>

#類別

類別說明
dial旋鈕本體,直徑 120px,套用於可取得焦點的 role="slider",需具備無障礙名稱、aria-valuenow、aria-valuemin 和 aria-valuemax。圓形軌道從起點到目前值以前景色填滿。預設為 270 度的旋鈕,開口朝下
dial-full完整的圓周,從頂端開始。適用於角度,超過最大值會再繞回搭配 dial 使用
dial-sm錶盤直徑為 88px,預設為 120px搭配 dial 使用
dial-lg160px 的錶盤,預設為 120px搭配 dial 使用
dial-thumb位於軌道上目前值角度的珠光滑塊,為空元素。取得焦點時會顯示焦點環;在滑塊上按下並轉動時,數值不會跳動
dial-value以文字顯示的數值,使用等寬數字置於旋鈕中央;每次變更時由行為寫入
dial-ticks空元素,在滑塊軌跡外側以細線繪製 --dial-ticks 個等分刻度
dial-mark位於外圈的簡短文字或數字,標示在其 --dial-at 所代表的數值位置

#自訂屬性

屬性預設值說明
--dial-value數值。支援具型別的 attr() 時取自 aria-valuenow;行為也會寫入此值
--dial-min0最小值。支援具型別的 attr() 時取自 aria-valuemin
--dial-max100最大值。支援具型別的 attr() 時取自 aria-valuemax
--dial-start225deg最小值所在的位置,從頂端順時針計算;dial-full 為 0deg。行為會讀取此值,將指標位置換算為數值
--dial-sweep270deg軌道從起點順時針延伸的角度;dial-full 為 360deg,讓數值可以繞回。行為也會讀取此值
--dial-size7.5rem錶盤直徑
--dial-trackcalc(var(--dial-size) / 20)軌道的粗細
--dial-thumb1.125rem滑塊圓鈕的直徑;整個旋鈕都會接收指標操作
--dial-colorvar(--color-surface-inverse)填色的顏色,軌道使用淡化的同色
--dial-ticks10刻度在整段角度範圍內標出的等分數設定於 dial-ticks
--dial-at0標記所在的數值設定於 dial-mark

#原始碼

@master/ui/components/dial.css
/* * Dial: a value set by turning a thumb around a circle, the input sibling of the gauge. * An element with role="slider" draws a round track in its fill's own ink, stepped back, fills it with ink from * where it starts to the value, and carries the slider's pearl thumb at the value's angle. The figure stands in * the middle in tabular figures. By default the dial is a knob: 270 degrees, open at the foot, from its least * value at the lower left to its greatest at the lower right. dial-full is the whole circle, from the top, for * an angle that comes round again. The script reads where it starts and how far it sweeps from this stylesheet. * Clockwise is more in every writing direction: a dial turns like a clock or a knob, so it is not mirrored. * Where the browser supports typed attr(), the dial reads aria-valuenow, aria-valuemin and aria-valuemax * itself; elsewhere it reads --dial-value, which the behavior writes with every change. The fill follows the * hand at once, with no easing: an input that lags behind the pointer feels broken. * A dial is 120px across (88 small, 160 large); its track is a twentieth of that, and its thumb is the slider's * 18px at every pointer: the whole dial takes the finger. Ticks and marks take a rim outside the thumb's path, so the dial keeps its size. */@property --dial-value {  syntax: '<number>';  inherits: true;  initial-value: 0;}@property --dial-start {  syntax: '<angle>';  inherits: true;  initial-value: 225deg;}@property --dial-sweep {  syntax: '<angle>';  inherits: true;  initial-value: 270deg;}@layer components.ui {  .dial {    --dial-size: 7.5rem;    --dial-track: calc(var(--dial-size) / 20);    --dial-thumb: 1.125rem;    --dial-color: var(--color-surface-inverse);    --dial-min: 0;    --dial-max: 100;    --dial-start: 225deg;    --dial-sweep: 270deg;    /* Room between the thumb's path and the edge, for ticks and marks; none without them. */    --dial-rim: 0rem;    /* How far along the track the value is, from nothing to all of it, and the angle that puts it at. */    --dial-share: clamp(0, calc((var(--dial-value) - var(--dial-min)) / (var(--dial-max) - var(--dial-min))), 1);    --dial-angle: calc(var(--dial-start) + var(--dial-share) * var(--dial-sweep));    /* The middle of the track, where the thumb's centre runs. */    --dial-radius: calc((var(--dial-size) - var(--dial-thumb)) / 2 - var(--dial-rim));    position: relative;    /* The thumb and the figure stand over the track within the dial, never over the page around it. */    isolation: isolate;    display: inline-grid;    flex: none;    place-items: center;    box-sizing: border-box;    width: var(--dial-size);    height: var(--dial-size);    margin: 0;    /* A circle takes the pointer, so the corners of its box do not. */    border-radius: 999px;    corner-shape: round;    color: var(--color-text-strong);    font: var(--font-weight-control) calc(var(--dial-radius) * .44)/1 var(--font-family-sans);    font-feature-settings: inherit;    font-variant-numeric: tabular-nums;    letter-spacing: -.02em;    text-align: center;    vertical-align: middle;    cursor: pointer;    /* A finger that turns the dial does not scroll the page, and a drag selects no text. */    touch-action: none;    -webkit-user-select: none;    user-select: none;    -webkit-tap-highlight-color: transparent;    @supports (x: attr(x type(*))) {      &[aria-valuenow] {        --dial-value: attr(aria-valuenow type(<number>), 0);      }      &[aria-valuemin] {        --dial-min: attr(aria-valuemin type(<number>), 0);      }      &[aria-valuemax] {        --dial-max: attr(aria-valuemax type(<number>), 100);      }    }    &:focus-visible {      outline: none;    }    /* Both drawings cover the dial, cut down to the track's ring. */    &::before, &::after {      --dial-inner: calc(var(--dial-radius) - var(--dial-track) / 2);      --dial-outer: calc(var(--dial-radius) + var(--dial-track) / 2);      content: '';      position: absolute;      inset: 0;      border-radius: 999px;      corner-shape: round;      mask: radial-gradient(circle, transparent calc(var(--dial-inner) - .5px), black var(--dial-inner), black var(--dial-outer), transparent calc(var(--dial-outer) + .5px));      pointer-events: none;    }    /*     * The track: the whole sweep, with a dot at each end to round it. It is drawn in the fill's own color and     * stepped back as one layer, so the dots and the arc never add up. Around the full circle the dots meet.     */    &::before {      --dial-end: calc(var(--dial-start) + var(--dial-sweep));      background:        radial-gradient(circle at calc(50% + var(--dial-radius) * sin(var(--dial-start))) calc(50% - var(--dial-radius) * cos(var(--dial-start))), var(--dial-color) calc(var(--dial-track) / 2 - .5px), transparent calc(var(--dial-track) / 2)),        radial-gradient(circle at calc(50% + var(--dial-radius) * sin(var(--dial-end))) calc(50% - var(--dial-radius) * cos(var(--dial-end))), var(--dial-color) calc(var(--dial-track) / 2 - .5px), transparent calc(var(--dial-track) / 2)),        conic-gradient(from var(--dial-start), var(--dial-color) var(--dial-sweep), transparent 0);      opacity: .12;    }    /* The fill: the same track as far as the value. Its dots have no radius at nothing, so an empty dial is an empty track. */    &::after {      --dial-cap: calc(var(--dial-track) / 2 * min(1, var(--dial-share) * 200));      background:        radial-gradient(circle at calc(50% + var(--dial-radius) * sin(var(--dial-start))) calc(50% - var(--dial-radius) * cos(var(--dial-start))), var(--dial-color) calc(var(--dial-cap) - .5px), transparent var(--dial-cap)),        radial-gradient(circle at calc(50% + var(--dial-radius) * sin(var(--dial-angle))) calc(50% - var(--dial-radius) * cos(var(--dial-angle))), var(--dial-color) calc(var(--dial-cap) - .5px), transparent var(--dial-cap)),        conic-gradient(from var(--dial-start), var(--dial-color) calc(var(--dial-share) * var(--dial-sweep)), transparent 0);    }    /* Ticks take a narrow rim outside the thumb's path; marks a wider one, outside the ticks. */    &:has(.dial-ticks) {      --dial-rim: .5rem;    }    &:has(.dial-mark) {      --dial-rim: 1.375rem;    }    &.dial-full {      --dial-start: 0deg;      --dial-sweep: 360deg;    }    &.dial-sm {      --dial-size: 5.5rem;    }    &.dial-lg {      --dial-size: 10rem;    }    &[aria-disabled="true"] {      opacity: .5;      cursor: not-allowed;    }    @media (forced-colors: active) {      --dial-color: Highlight;      forced-color-adjust: none;      color: CanvasText;      &::before {        --dial-color: GrayText;        opacity: 1;      }      /* The dial is out of forced colors, so its figure and its marks are given the system's disabled ink too. */      &[aria-disabled="true"] {        --dial-color: GrayText;        color: GrayText;      }    }  }  /* The thumb: the slider's pearl disc, standing on the track at the value's angle. */  .dial-thumb {    position: absolute;    z-index: 1;    top: calc(50% - var(--dial-radius) * cos(var(--dial-angle)));    left: calc(50% + var(--dial-radius) * sin(var(--dial-angle)));    box-sizing: border-box;    width: var(--dial-thumb);    height: var(--dial-thumb);    translate: -50% -50%;    border-radius: 999px;    corner-shape: round;    @apply --surface-thumb;    box-shadow: 0 0 0 .5px var(--color-line-strong), 0 1px 2px -.5px var(--color-shade-1), 0 2px 4px -1px var(--color-shade-2), 0 4px 8px -4px var(--color-shade-3);    transition: scale var(--duration-quick) var(--easing-glide);    /* Held, the thumb grows a little under the finger. */    .dial:active:not([aria-disabled="true"]) & {      scale: 1.08;    }    /* Focus rings the thumb, as it does on a slider: the thumb is what the keys move. */    .dial:focus-visible & {      @apply --focus-ring;    }    @media (prefers-reduced-motion: reduce) {      transition: none;      .dial:active:not([aria-disabled="true"]) & {        scale: none;      }    }    @media (forced-colors: active) {      background: ButtonText;      box-shadow: 0 0 0 1px Canvas;      .dial:focus-visible & {        outline-color: Highlight;      }      /* Disabled, the thumb takes the system's disabled ink with the fill, as a slider's thumb does. */      .dial[aria-disabled="true"] & {        background: GrayText;      }    }  }  /* The value as text, in the dial's own figures, in the middle. */  .dial-value {    position: relative;    z-index: 1;    max-width: calc(var(--dial-radius) * 1.4);    overflow: hidden;    text-overflow: ellipsis;    white-space: nowrap;  }  /*   * Ticks: --dial-ticks equal steps across the sweep, as fine lines in the rim just outside the thumb's path.   * A knob shows one more tick than steps, at both ends; the full circle shows as many as steps.   */  .dial-ticks {    --dial-ticks: 10;    --dial-tick-inner: calc(var(--dial-size) / 2 - var(--dial-rim) + .125rem);    --dial-tick-outer: calc(var(--dial-tick-inner) + .3125rem);    position: absolute;    inset: 0;    border-radius: 999px;    corner-shape: round;    color: var(--color-line-mark);    /* Each tick is feathered at its sides: a hard stop in a conic gradient draws a jagged line. */    background: repeating-conic-gradient(from calc(var(--dial-start) - .75deg), transparent 0, currentColor .3deg 1.2deg, transparent 1.5deg calc(var(--dial-sweep) / var(--dial-ticks)));    mask:      radial-gradient(circle, transparent calc(var(--dial-tick-inner) - .5px), black var(--dial-tick-inner), black var(--dial-tick-outer), transparent calc(var(--dial-tick-outer) + .5px)),      conic-gradient(from calc(var(--dial-start) - 1deg), black calc(var(--dial-sweep) + 2deg), transparent 0);    mask-composite: intersect;    pointer-events: none;    @media (forced-colors: active) {      color: GrayText;    }  }  /* A mark: a short word or figure in the rim, at the value --dial-at stands for. */  .dial-mark {    --dial-at: 0;    --dial-mark-angle: calc(var(--dial-start) + clamp(0, calc((var(--dial-at) - var(--dial-min)) / (var(--dial-max) - var(--dial-min))), 1) * var(--dial-sweep));    --dial-mark-radius: calc(var(--dial-size) / 2 - .4375rem);    position: absolute;    top: calc(50% - var(--dial-mark-radius) * cos(var(--dial-mark-angle)));    left: calc(50% + var(--dial-mark-radius) * sin(var(--dial-mark-angle)));    translate: -50% -50%;    color: var(--color-text-muted);    font: 400 .6875rem/1 var(--font-family-sans);    font-feature-settings: inherit;    font-variant-numeric: tabular-nums;    letter-spacing: 0;    white-space: nowrap;    pointer-events: none;    @media (forced-colors: active) {      color: CanvasText;      .dial[aria-disabled="true"] & {        color: GrayText;      }    }  }}