vael-ui v0.5.7

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>

Parameters

NameTypeDescription
modelRef<number>The value. It changes by step for every degreesPerStep of rotation, and on key presses.
dialElRef<HTMLElement | null>The round element. Pointer angles are measured around its center.
min / maxMaybeRefOrGetter<number | undefined>The bounds. Each side clamps on its own. Unset by default, so the value is unbounded.
stepMaybeRefOrGetter<number>The change per notch. Default 1.
degreesPerStepMaybeRefOrGetter<number | undefined>The rotation per step. Lower turns faster. Default DIAL_DEFAULT_DEGREES_PER_STEP (15).
disabledMaybeRefOrGetter<boolean>Ignores pointer and keyboard input.
onCommit() => voidFires once per settled interaction: on release, or after each key press. <Dial> re-emits it as change.

Returns

NameTypeDescription
isDraggingRef<boolean>true from pointer down to release.
rootStyleComputedRef<Record<string, string>>Bind it on your root: --ui-dial-rotation, the dial's own rotation in degrees, which keeps counting past 360°, and --ui-dial-fraction (0 to 1) when both bounds are set.
fractionComputedRef<number | undefined>The progress from 0 to 1, or undefined when the range is open on either side.
onDialPointerdown(event: PointerEvent) => voidBind it on the dial. It tracks the drag on the window until release.
onDialKeydown(event: KeyboardEvent) => voidBind it on the focusable element.