vael-ui v0.5.7

Forms & inputs

Layout

Knob

A rotary control that sets a number within a fixed arc. Use it for bounded values, such as a volume or a level.

Validating a form? vael-form wires this up with a schema

Install

import { Knob } from 'vael-ui'

Playground

Placement, behaviour and animation

Usage
<script setup lang="ts">
import { ref } from 'vue'
import { Knob } from 'vael-ui'

const value = ref(0)
</script>

<template>
  <Knob aria-label="Volume" v-model="value" />
</template>

Props

NameTypeDefaultDescription
minnumber0Lowest allowed value.
maxnumber100Highest allowed value.
stepnumber1Increment the value snaps to; arrow keys move one step, Page Up/Down ten.
size'sm' | 'md' | 'lg''md'Control size.
disabledbooleanfalseDisables the knob and blocks interaction.
invalidbooleanfalseShows the invalid state. A surrounding Field in error sets it too.
namestringNative name for form submission, via a hidden input.
valueText((value: number) => string)Drives aria-valuetext, e.g. (v) => \${v} dB\`` for a gain knob.
uiPartial<Record<'root' | 'dial' | 'track' | 'fill' | 'indicator', UiPartValue>>Class and style overrides for each part.
motionKnobMotionHow it moves: its appearance ({ initial: { root: { opacity: 0, scale: 0.9 } } }) and its states, like active while you turn it ({ states: { active: { indicator: { scale: '1.2' } } } }). false turns its own animation off.
modelValuenumber0Current value.

Events

NameTypeDescription
update:modelValue(value: number)Fires when modelValue changes (v-model).
change(value: number)Fires with the final value when you release the knob or press a key, like a native range input's change. v-model updates on every move.

Slots

No slots.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
dialElHTMLElement | nullFocusable dial element (role="slider").
indicatorElHTMLElement | nullPointer mark that rotates with the value.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

Knob: its appearance, states and the fill's timing.

<Knob
  :motion="{ states: { disabled: { root: { scale: 1.04 } } } }"
/>
NameTypeDescription
initialexitroottrackfillindicatorSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
statesdisabledfocusactiveSets values per part that hold while a state is on. An array is a set of keyframes that plays once as the state turns on, such as a shake on invalid.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

Follows the Slider pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
ArrowRightArrowUpIncreases the value by one step.
ArrowLeftArrowDownDecreases the value by one step.
PageUpIncreases the value by ten steps.
PageDownDecreases the value by ten steps.
HomeSets the value to min.
EndSets the value to max.
  • The dial has role="slider" with aria-valuenow, aria-valuemin and aria-valuemax, and aria-invalid when invalid. Pass valueText to set aria-valuetext.
  • Inside a Field, the label names the dial. Without one, pass aria-label: it moves from the wrapper to the dial.
  • Pressing the dial focuses it.
  • The arrow keys don’t swap right to left.