Slider

Slider

HkSlider is the range control for settings and forms: a rail, a persistent thumb, a fill up to the thumb and optional tick dots, with the value snapped onto a step grid anchored at min. Clicking the rail jumps the thumb there and dragging moves it continuously; the arrow keys step, Page Up / Page Down step four times over and Home / End jump to the ends. It is controlled only — pass modelValue and wire update:modelValue.

  • For a number typed or nudged with buttons, use HkNumberInput.
  • For a number with its own caption line and validation message, wrap this control in HkFormField.
  • For a two-state setting, use HkSwitch.

Import

tsx
1
import { HkSlider } from "@celestia-island/hikari";
rust
1
2
use hikari_components::*;          // Slider, SliderSize, Callback
use hikari_components::prelude::*; // rsx!, VNode

The Rust form is a plain function, Slider(SliderProps { … }). Two naming differences: Vue calls the value modelValue (a required prop) and the mirror calls it value: f64, defaulting to 0.0 so the props struct stays Default-constructible; and the live emit update:modelValue becomes on_input, which fires continuously while dragging, exactly like Vue.

Value, bounds and step

min and max bound the range (0 and 100 by default), and step is the snap grid — emitted values are always min + n * step. A non-positive step falls back to 1. Both the value passed in and the value reported back are clamped into [min, max] and snapped, so an off-grid modelValue is drawn on the nearest stop rather than where it was given. The Vue example is live: drag the thumbs and the readout follows.

60 % · opacity 0.5

Ticks, sizes and the value text

showTicks draws one dot per stop, with the stops already crossed marked active. The dots are only drawn for a readable stop count — fewer than two stops, or more than thirty-two, renders the rail bare, so a 0–100 range at step 1 stays clean. size is sm or md (the default); there is no lg step. formatValue supplies the spoken form of the value (the aria-valuetext), which is how a percentage or a unit gets announced instead of a bare number.

The Rust mirror takes the same formatter as format_value, a Callback<f64, String>: Callback::new wraps one function from a number to its spoken text.

Vertical, disabled and drag tracking

vertical stands the rail upright: values climb bottom to top, the thumb and ticks ride top instead of left, the fill's extent becomes height, and the root announces aria-orientation="vertical". The host sizes the height — the control has no intrinsic one — so the example gives it a stage. disabled dims the rail, takes it out of the Tab order and silences pointer and keyboard alike.

The Rust mirror tracks a drag through the root element's own mouse events: a drag that leaves the track stops emitting until the pointer comes back, and a release outside is recovered from the button state, so a later hover never writes a value. Vue attaches its move and release listeners to the window instead, which is why a drag keeps tracking past the element there.

API

Vue

Props

NameTypeDefaultRequired
modelValueNumber—✓
minNumber0—
maxNumber100—
stepNumber1—
disabledBooleanfalse—
showTicksBooleanfalse—
size<code>String as () => "sm" | "md"</code>"md"—
verticalBooleanfalse—
ariaLabelStringundefined—
formatValueFunction as PropType<(value: number) => string>undefined—

Emits

EventPayload
update:modelValuenumber

Rust

Props — Slider

PropTypeDefaultDescription
valuef640.0Controlled value (Vue: modelValue, required there; 0.0 here because Rust props need a Default).
minf640.0—
maxf64100.0—
stepf641.0Snap step; non-positive values fall back to 1 (Vue's safeStep).
disabledboolfalse—
show_ticksboolfalseRender one tick dot per stop (Vue: showTicks).
sizeSliderSizeSliderSize::Md—
verticalboolfalseStand the rail upright (Vue: vertical, default false): values climb bottom→top, the thumb and ticks ride top, the fill's extent is height, the root announces aria-orientation="vertical" and the pointer maps off the track's bottom edge.
aria_labelOption<String>Nonearia-label (Vue: ariaLabel); omitted when None.
format_valueOption<Callback<f64, String>>Nonearia-valuetext formatter (Vue: formatValue).
on_inputOption<EventHandler<f64>>NoneEmitted with the snapped value while interacting (Vue: update:modelValue, emitted continuously like Vue's drag/keyboard path).
classString""Vue attribute fallthrough onto the root <div>.
styleString""—

Accessibility

  • The root is a <div role="slider"> with aria-valuemin, aria-valuemax, aria-valuenow and aria-valuetext, so the current value is read out on focus and on every change.
  • aria-valuetext is the number's own rendering unless formatValue is given; pass one whenever the raw number is not what the user hears (a percentage, a unit, a word).
  • Pass ariaLabel: the control has no visible caption of its own and would otherwise be announced only by its role and value.
  • The root is focusable (tabindex="0", and -1 while disabled), and the arrows, Page Up / Page Down and Home / End all move it; aria-orientation="vertical" is set only in vertical mode, and the keyboard is unchanged there — Up and Right both increase.
  • formatValue is called for the spoken value only; it never changes the number that is emitted.

Related components

  • HkFormField — the caption and message shell for a control that needs a label line.
  • HkNumberInput — the same scalar typed or stepped instead of dragged.
  • HkSwitch — the two-state setting.
  • HkCheckbox — the independent on/off choice.