导航

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 会停在最大值前一个步长处。

角度

<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 的文字
wheeltrue 允许在按住 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 度”“响亮”。行为脚本会让它与数值保持同步。
  • 滑块内部的一切,包括数字、刻度和标记,对辅助技术而言都只是展示内容。按键可以完成拖动能做的一切,在轨道上单击一次即可设置数值,因此无需拖动也能调节旋钮。
  • 与滑块一样,焦点环绘制在滑钮上。在触摸屏上,整个旋钮都接收手指操作,转动旋钮而不是滚动页面,因此滑钮保持原有尺寸。
  • 启用减少动态效果时,按住的滑钮不会放大。在强制颜色模式下,填充使用系统高亮色,轨道和刻度使用系统灰色,滑钮使用按钮文字颜色。

#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,应用于可聚焦且带无障碍名称、aria-valuenow、aria-valuemin 和 aria-valuemax 的 role="slider":圆形轨道从起点到当前值以墨色填充。默认是 270 度的旋钮,底部留有缺口
dial-full从顶部开始的完整圆周:用于角度,超过最大值后会回到起点与 dial 一同使用
dial-sm88px 表盘,默认为 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;      }    }  }}