Dial
A value set by turning a thumb around a circle: a level set like a knob, an angle or a direction.
On this page
A dial sets a value by turning a thumb around a circle: a level set like a knob, an angle, a direction. It is the input sibling of the gauge: a round track in the fill's own ink, stepped back, fills with ink from where it starts to the value, and the slider's pearl thumb stands on it at the value's angle. The figure sits in the middle in tabular figures. There is no native element for it, so the dial is an element with role="slider", and the dial behavior turns it.
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>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. A press on the track moves the value there; a press on the thumb takes hold of it where it is, so it turns without a jump. A drag that goes past an end stays at that end, through the gap at the foot, until the pointer comes back.
#An angle
dial-full is the whole circle, starting at the top: an angle or a direction, from aria-valuemin 0 to aria-valuemax 360. Past its greatest value it comes round to the least again, from the keys and from a drag through the top, and 360 is written as 0, the same place. End stops a step before it.
An angle
<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>The label and aria-valuetext keep the words they were written with around the number, so "135°" becomes "136°" with no script of the page's. For words of another kind, pass the behavior a text function, as the behavior shows.
#Ticks and marks
A dial-ticks element draws --dial-ticks equal steps across the sweep as fine lines just outside the thumb's path: a knob shows one more tick than steps, one at each end, and the full circle as many as steps. A dial-mark is a short word or figure in the rim, placed by the stylesheet at the value its --dial-at stands for. Both take a rim inside the dial's box, so the track grows smaller around them; give a dial with marks the large size.
Ticks and marks
<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>Ticks and marks are drawings: inside a role="slider" they are not announced, so the value and its words must say everything a mark says.
#Sizes
A dial is 120px across. dial-sm is 88px, for a row of controls, and dial-lg is 160px, for the one value a panel is about or a dial with marks. The track is a twentieth of the width and the figure scales with the track; the thumb keeps the slider's 18px at every pointer.
Sizes
<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>#In a form
A role="slider" is not a form control, so the dial carries a hidden input. The behavior writes the value into the first <input type="hidden"> inside the dial with every change, and a form submits it under the input's name. The dial's input and change events bubble to the form like a native control's. A form's reset does not reach a hidden input, so the dial stays where it was; set its value again from the page if a reset should move it.
In a form
<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>A visible label is an element of its own, pointed at with aria-labelledby: a <label> names only form controls. Show the range in words beside the dial when it is not plain from the figure.
#Disabled
aria-disabled="true" fades the dial and leaves it out of every key, pointer and wheel. Take it out of the tab order with tabindex="-1", and put disabled on its hidden input too, so a form does not submit the value.
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>#Which way it turns
Clockwise is more, in every writing direction. A dial turns like a clock or a knob on a device, and those are not mirrored from right to left, so the dial is not either, and its arrow keys do not turn around: → and ↑ always turn it up. At the top of the dial, where the eye starts, clockwise is the way to the right; that is the arrow that turns it there.
#The behavior
dial takes the root, the element with the dial class, and returns the function that detaches it. The function has a value, the number: set it to turn the dial from outside, which dispatches nothing.
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))- Each change writes the value to
aria-valuenowand--dial-valueon the root, to the text ofdial-value, toaria-valuetextwhen there is one ortextis given, and to the hidden input. As it attaches, it writes the first value the same way, and copiesaria-valueminandaria-valuemaxto--dial-minand--dial-maxfor a browser that cannot read the attributes. - The value stays on a step from
aria-valuemin, between it andaria-valuemax, 0 and 100 when they are left out; round a full circle it comes round instead. - Dragging. On
pointerdownit captures the pointer and reads its angle around the middle of the dial, which it turns into a value with the same--dial-startand--dial-sweepthe stylesheet draws with. A dial whose sweep is 360 degrees comes round, with or withoutdial-full. A press near the middle, on the figure, does not move the value. - The keys. The arrows turn by a step, Page Up and Page Down by a larger one, and Home and End go to the ends.
- The wheel, when it is asked for, turns the dial a step for each notch, but only while Alt (Option) is held: scrolling a page past a dial never turns it.
- Events. The root dispatches
inputeach time the value changes, andchangewhen a drag ends or a key or the wheel turned it. Both bubble. - Disabled. A dial with
aria-disabled="true"takes no key, pointer or wheel.
| Option | What it sets |
|---|---|
step | How far an arrow key turns the value, and what a drag rounds it to. 1 by default |
page | How far Page Up and Page Down turn it. A tenth of the range by default, on a step |
text | A function from the value to its words, written in dial-value and in aria-valuetext |
wheel | true lets a wheel turn the dial while Alt is held. false by default |
attach() passes no options. A dial that needs them is attached by itself, after attach() has run: a second call on one root replaces the first, as this preview's script does. MasterUI is the bundle a preview loads; in a project, import dial as above.
Steps, words and the wheel
<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>Without the behavior a dial shows its first value, from its attributes where the browser supports typed attr() and from --dial-value elsewhere, and does not turn.
#Keyboard
| Keys | Action |
|---|---|
| ArrowUp, ArrowRight | Turn the value up by a step, clockwise in every writing direction; around a full circle, past the greatest value it comes round to the least |
| ArrowDown, ArrowLeft | Turn the value down by a step, anticlockwise; around a full circle, below the least it comes round to the greatest |
| PageUp, PageDown | Turn the value up or down by a larger step, a tenth of the range unless the page sets another |
| Home, End | Move to aria-valuemin or aria-valuemax; around a full circle, End is the last step before the value comes round |
#Accessibility
- The root is a focusable
role="slider"with an accessible name, fromaria-labeloraria-labelledby, and the value inaria-valuenowbetweenaria-valueminandaria-valuemax. A slider has no orientation that means anything round a circle, so leavearia-orientationout. - When the number needs a unit or words to be understood, write
aria-valuetext: "135°", "21 degrees", "Loud". The behavior keeps it in step with the value. - Everything inside the slider, the figure, the ticks and the marks, is presentation to assistive technology. The keys do everything a drag does, and a single press on the track sets a value, so turning by dragging is never the only way.
- Focus rings the thumb, as on a slider. On touch screens the whole dial takes the finger and turns instead of scrolling the page, so the thumb keeps its size.
- With reduced motion the held thumb does not grow. In forced colors the fill takes the system highlight, the track and the ticks the system's grey, and the thumb the button text color.
#React, Svelte and Vue
The dial component attaches the behavior and passes the value in and out. It renders the ticks and the marks from data, and the hidden input when it is given a name. Copy it into the project with npx master-ui add dial; React, Svelte and Vue says how the components are built and used.
#Related
- SliderA native range input: a thin well with a pearl thumb.
- GaugeA reading on a dial: an arc that fills as far as the value has come.
- StepperA number between the two buttons that step it.
#Classes
| Class | Description |
|---|---|
dial | The dial, 120px across, on a focusable role="slider" with an accessible name, aria-valuenow, aria-valuemin and aria-valuemax: a round track filled with ink from its start to the value. By default a knob of 270 degrees, open at the foot |
dial-full | The whole circle, starting at the top: an angle, which comes round again past its greatest valueApply with dial |
dial-sm | An 88px dial; the default is 120pxApply with dial |
dial-lg | A 160px dial; the default is 120pxApply with dial |
dial-thumb | The pearl thumb on the track at the value's angle, an empty element. Focus rings it, and a press on it turns the dial without a jump |
dial-value | The value as text, in tabular figures at the middle of the dial; the behavior writes it with every change |
dial-ticks | An empty element that draws --dial-ticks equal steps as fine lines just outside the thumb's path |
dial-mark | A short word or figure in the rim, at the value its --dial-at stands for |
#Custom properties
| Property | Default | Description |
|---|---|---|
--dial-value | The value. It comes from aria-valuenow where typed attr() is supported; the behavior writes it too | |
--dial-min | 0 | The least value. It comes from aria-valuemin where typed attr() is supported |
--dial-max | 100 | The greatest value. It comes from aria-valuemax where typed attr() is supported |
--dial-start | 225deg | Where the least value stands, clockwise from the top; 0deg on dial-full. The behavior reads it to turn a pointer into a value |
--dial-sweep | 270deg | How far the track runs from the start, clockwise; 360deg on dial-full, which makes the value come round. The behavior reads it too |
--dial-size | 7.5rem | The dial's diameter |
--dial-track | calc(var(--dial-size) / 20) | Thickness of the track |
--dial-thumb | 1.125rem | Thumb diameter; the whole dial takes the pointer |
--dial-color | var(--color-surface-inverse) | The ink of the fill; the track is the same color stepped back |
--dial-ticks | 10 | How many equal steps the ticks mark across the sweepSet on dial-ticks |
--dial-at | 0 | The value a mark stands atSet on dial-mark |