Used with a component · Dial
useDial
The headless engine behind <Dial>: a value you turn like a jog wheel, with no fixed sweep. Each degreesPerStep of rotation (15° by default, a mouse wheel's detent) is one step. Leave min and max unset for a value that keeps counting in either direction, or set either one to clamp that end. The dial's own rotation keeps following the pointer even when the value stops at a bound, so it never stalls under your finger. It renders nothing: bind rootStyle and draw from --ui-dial-rotation and, when both bounds are set, --ui-dial-fraction.
Install
import { useDial, DIAL_DEFAULT_DEGREES_PER_STEP } from 'vael-ui'Examples
<script setup lang="ts">
import { ref, useTemplateRef } from 'vue'
import { useDial } from 'vael-ui'
const zoom = ref(100)
const dialEl = useTemplateRef<HTMLElement>('dial')
const { rootStyle, onDialPointerdown, onDialKeydown } = useDial(zoom, {
dialEl,
min: 10,
step: 5,
})
</script>
<template>
<div
ref="dial"
class="my-dial"
role="slider"
tabindex="0"
aria-label="Zoom"
:aria-valuenow="zoom"
:style="rootStyle"
@pointerdown="onDialPointerdown"
@keydown="onDialKeydown"
>
<span class="my-dial-notch" />
</div>
</template>
<style>
.my-dial-notch {
rotate: var(--ui-dial-rotation);
}
</style>