GhostSlider specification
Status: Proposed for GHO-88. Spec and implementation ship together; Zac approves both in PR review.
Amendment (approved 2026-12-04, no target release yet): a narrower
update:modelValuetype keyed onrangeis specified in the Narrowed v-model typing amendment.
Purpose and user problems
GhostSlider is a range input with WAI-ARIA slider semantics. It lets users pick one numeric value along a bounded axis, or two values that define an interval. Assistive technology encounters role="slider" with aria-valuemin, aria-valuemax, and aria-valuenow (and optional aria-valuetext). Sighted users drag thumbs along a track. Immediate consumers include numeric range filters in data tables and settings where a continuous or stepped value is clearer than a free-text field.
The control participates in native HTML forms through hidden inputs, and form.reset() restores the mounted defaults via the same policy as GhostInput and GhostCheckbox.
Non-goals
- It is not a progress indicator (
GhostProgress) or meter. Values are edited, not displayed. - It is not a native
<input type="range">. Native range inputs are a replaced element with uneven styling and no stabledata-partchildren for theming. - It does not own labeling primitives (
GhostField, GHO-71). Consumers supply names througharia-label,aria-labelledby, or visible labels associated with the control. - It does not implement tick marks, value labels along the track, or an editable numeric companion field. Those are composition.
- It does not implement time or date picking;
min/max/stepare plain numbers in the same unit the consumer chooses. - The unstyled component ships minimal layout only (percentage-positioned thumbs and an optional range fill). Track cosmetics belong to the themed wrapper.
Public API
Props and configuration
Headless @ghostvue/vue GhostSlider / useGhostSlider:
| Prop | Type | Default | Contract |
|---|---|---|---|
modelValue | number | [number, number] | omitted | Controlled value. Single-thumb mode uses a number; range mode uses a readonly two-tuple [minThumb, maxThumb]. Omitted is uncontrolled. |
defaultValue | same as modelValue | min or [min, max] in range mode | Initial value when modelValue is omitted. Captured at mount for reset; later prop changes ignored. |
min | number | 0 | Lower bound. Must be finite and <= max after coercion. |
max | number | 100 | Upper bound. Must be finite and >= min. |
step | number | 1 | Snap increment. Must be finite and > 0; invalid values fall back to 1. |
range | boolean | false | When true, two thumbs select an interval; modelValue / defaultValue use tuples. |
orientation | 'horizontal' | 'vertical' | 'horizontal' | Maps to aria-orientation and keyboard axis. |
disabled | boolean | false | Native disabled: thumbs not operable, not focusable, hidden inputs not submitted. |
name | string | omitted | Form field name for the primary (or only) value. Hidden type="hidden". |
nameMax | string | omitted | In range mode, form field name for the high thumb. Ignored when range is false. |
form | string | omitted | Associates hidden inputs with an external form id. |
valueText | string | omitted | Optional aria-valuetext for the focused thumb when set; per-thumb overrides may use fallthrough on a thumb. |
Native attributes and listeners fall through to the root track container (data-part="root"). The component owns aria-orientation on the root when vertical, thumb role / value attributes, and data-state hooks. Do not redeclare owned ARIA as camelCase props except valueText on the composable for the simple single-thumb case.
Named ESM exports: GhostSlider, useGhostSlider, and the types above. Headless behavior lives in the composable; the SFC renders root, track, optional data-part="range" fill, one or two data-part="thumb" hosts with role="slider", and hidden form inputs.
Themed @ghostvue/themes GhostSlider wraps the unstyled component and adds visual props:
| Prop | Type | Default | Contract |
|---|---|---|---|
size | 'sm' | 'md' | 'lg' | 'md' | Track thickness and thumb size. Default omits data-size. |
tone | 'accent' | 'neutral' | 'danger' | 'accent' | Selected range and thumb color intent. Default omits data-tone. |
Themed geometry comes from density-independent painted tokens, never layout gaps (which collapse to zero at compact density): track and range share --ghost-track-thickness-sm / md / lg (4 / 6 / 8px) and are centered on the rail; the thumb uses --ghost-track-thumb-sm / md / lg (12 / 16 / 20px). Pointer targets are separate from paint: transparent ::before hit areas grow the track's cross axis and the thumb to at least --ghost-track-target (24px) without affecting layout, the focus outline, or the track rect used to map pointer position to a value.
v-model contracts
v-model binds modelValue / update:modelValue.
- Omitted
modelValueis uncontrolled. Local state starts atdefaultValue(single:min; range:[min, max]unlessdefaultValueis provided). - A defined
modelValueis controlled. Writes emitupdate:modelValueand do not update local state when controlled. - Assignment is skipped when the snapped value is unchanged (
Object.isfor numbers; tuple compared by element withObject.is). - Switching controlled/uncontrolled at runtime logs
GHOST001in development. - Form reset restores the mount-captured
defaultValue, usingnextTickbefore reconciling hidden input DOM when controlled, matchingGhostCheckbox/GhostInput.
Events, callbacks, slots, and exposed methods
No extra events besides update:modelValue. Pointer and keyboard interaction on thumbs update the model.
The default slot is optional inner content (for example a visible label inside the control). Prefer sibling <label> or aria-labelledby when the name should sit outside the track.
Template ref (GhostSliderExposed):
element: rootHTMLElement | nullvalue: current number or readonly tuple (mirrors the model)focus(options?): focuses the first enabled thumbblur(): blurs the active thumb if inside the control
Value snapping and range invariants
Values are clamped to [min, max] and snapped to the nearest valid step from min. In range mode the low thumb never exceeds the high thumb; crossing attempts move the opposite thumb or clamp at the collision.
Page Up / Page Down use a large step of max(step * 10, (max - min) / 10) unless step already equals the full span.
State model
Disabled suppresses pointer and keyboard changes and removes thumbs from the tab order. Read-only is out of scope for v1 (unlike GhostSwitch).
data-state on the root is omitted; thumbs may set data-focus when focused for theming.
Accessibility contract
Semantics and relationships
Follows Slider and Multi-Thumb Slider patterns.
- Root:
div.ghost-sliderwithdata-part="root". Noroleon the root. - Each thumb:
divwithrole="slider",tabindex="0"when enabled,aria-valuemin,aria-valuemax,aria-valuenow, optionalaria-valuetext, optionalaria-orientationwhen vertical. - In range mode each thumb gets its own effective min/max (low thumb max is high value; high thumb min is low value).
- Track and range fill:
aria-hidden="true". - Hidden inputs: not focusable; participate in forms only.
Keyboard interaction
On the focused thumb (APG slider):
| Key | Horizontal LTR | Horizontal RTL | Vertical |
|---|---|---|---|
| Arrow toward max | ArrowRight | ArrowLeft | ArrowUp |
| Arrow toward min | ArrowLeft | ArrowRight | ArrowDown |
| Large step toward max | PageUp | PageUp | PageUp |
| Large step toward min | PageDown | PageDown | PageDown |
| Minimum | Home | Home | Home |
| Maximum | End | End | End |
RTL is resolved from dir on the root or an ancestor, same as useRovingFocus. Arrow keys do not move focus between thumbs; Tab moves to the next thumb in range mode.
Focus behavior
Thumbs are in document tab order. Focus outline is the consumer's or theme's responsibility on [data-part="thumb"].
Assistive technology expectations
Value changes update aria-valuenow immediately. Consumers should provide an accessible name on the root via fallthrough aria-label / aria-labelledby.
Rendering and customization
Headless data-part hooks:
| Part | Description |
|---|---|
root | Positioning context and attribute fallthrough host |
track | Full span of the axis |
range | Selected interval fill (range mode or single fill from min) |
thumb | Draggable value handle (data-thumb-index 0 | 1) |
Thumbs are positioned with inline axis percentage and centered along the inline axis according to the resolved text direction (-50% in LTR, +50% in RTL, reacting to dir changes on the root or ancestors). Vertical sliders use block axis percentage on the thumb and apply the same direction-aware inline centering to both the rail and thumb.
Themed width: a horizontal @ghostvue/themes GhostSlider follows the form control width rule. The wrapper removes the headless inline inline-size: 12rem, so a GhostField stretches the slider, and the recipe keeps 12rem as the root's content width elsewhere. Because no inline size remains, a consumer inline-size from class or style applies. Vertical sliders keep the headless size.
Environment behavior
SSR and hydration
No window in setup. Values render deterministically from props/state. Pointer listeners attach on mount.
Mobile and touch
Pointer drag on thumbs is supported. Touch follows the same snapping rules.
Performance
Single- and two-thumb instances only; no virtualization.
Composition
useControllableStatefor the model.useNativeFormReset+afterNativeFormResetpolicy fromform-reset.ts.- Does not use
useRovingFocus; slider arrows adjust values, not focus. useGhostIdis unused in v1.
Test plan
- Unit tests: snapping, step/page step, range invariants, controlled emit, uncontrolled local writes, RTL arrow mapping, form hidden values, reset baseline.
- Browser: keyboard on playground, form submit/reset, axe on playground section and each registry example (light/dark).
- Cross-browser (
@cross-browser, Chromium, Firefox, WebKit): thumb and rail geometry in LTR and RTL, pointer drags mapped to values in horizontal (single and range) and vertical sliders in both directions, vertical sliders ignoring ArrowLeft/ArrowRight, and reactivedir. Assertions use bounding boxes andaria-valuenow, not inline styles. - Known engine difference: Firefox reports integer mouse coordinates, so a pointer placed exactly on a fractional track edge can land up to one pixel inside the track (value 1 instead of 0 on a 100px track). Endpoint drags in the e2e spec overshoot the edge, which clamps in every engine; interior targets are asserted within 1.5px.
- Type tests:
GhostSliderPropsfallthrough and v-model types. - Themed integration:
elementref targets the unstyled root inside the scope.
Documentation plan
- API reference at
docs/components/slider.md - Examples:
slider/basic(single),slider/range,slider/vertical - Playground section
GhostSliderwith unique status strings
Compatibility and release impact
New minor features on @ghostvue/vue and @ghostvue/themes. Changeset required.
Open architectural questions
None blocking v1. Multi-thumb label composition (one name vs per-thumb) is left to consumer aria-labelledby until GhostField exists.
Narrowed v-model typing amendment
Important
Approved 2026-12-04, no target release yet. The maintainer approved the recommended option for each of Q1–Q4 in PR #775. This amendment narrows the type of the update:modelValue payload so that v-model on a number ref compiles under vueCompilerOptions.strictTemplates. Only public types change, not runtime behavior. It delivers the contract and acceptance cases; the implementation waits for a target release. The Select amendment is approved alongside it, and the two share the strict-templates fixture described in the TypeScript standard.
Problem
Both the headless and the themed GhostSlider emit GhostSliderValue (number | readonly [number, number]) whatever range is. A single-thumb slider bound to ref<number> is the ordinary case, and under strict templates it fails. The ModelUnions.vue fixture in packages/themes/type-tests-strict/ reports, on the current master:
ModelUnions.vue(18,33): error TS2322: Type 'GhostSliderValue' is not assignable to type 'number'.
Type 'readonly [number, number]' is not assignable to type 'number'.
ModelUnions.vue(19,25): error TS2322: Type 'GhostSliderValue' is not assignable to type 'number'.Line 18 is the headless slider and line 19 the themed one. Today a strict consumer has to widen the ref to GhostSliderValue, or replace v-model with a handler that narrows with typeof.
Why narrowing is sound
The runtime already ties the emitted shape to range. Every value the slider emits goes through normalizeModel in use-ghost-slider.ts. With range false it returns one snapped number, and with range true an ordered two-number tuple. This holds whatever shape modelValue or defaultValue had, so a tuple passed to a single slider is emitted back as a number. Changing range after mount emits nothing: the slider reads the model through the new mode at once, but the bound ref keeps its old shape until the next user change, which then emits the new shape. This amendment narrows only the payload type, so it needs no runtime change for that case. The payload type therefore depends on range alone. An omitted range or the bare range attribute fixes it at compile time. A boolean expression does not, so it keeps the union.
Options considered
| Option | Strict v-model on ref<number> | Cost and risk |
|---|---|---|
A. Generic SFC keyed on range (recommended) | Compiles | Same pattern as GhostSelect's multiple. A generic SFC is typed as a function, so InstanceType<typeof GhostSlider> stops working for the headless export. The manifest shows the prop type as Range, as Select's shows Multiple. The themed wrapper needs a cast. |
| B. Keep a plain SFC and cast the headless export to an overloaded construct signature | Compiles | Keeps InstanceType, but adds a hand-written cast to @ghostvue/vue, which has none today. vue-component-meta reads the SFC, not the cast, so manifests and docs tables would describe a different type from the one consumers get. |
C. Separate GhostRangeSlider component | Compiles | Two components with one behavior, a duplicate capability. Every range consumer has to migrate. |
D. Infer the payload from the modelValue type (generic="T extends GhostSliderValue") | Compiles | Unsound. The payload follows range, not the bound value, so <GhostSlider v-model="volume" range> would type-check and then write a tuple into a ref<number>. |
| E. Keep the union and document a wide ref | Fails | No change, but the strict-templates gap stays. |
Proposed contract
Headless SFC.
GhostSlider.vuebecomes<script setup lang="ts" generic="Range extends boolean = false">. The prop is declaredrange?: Range & boolean: as with Select'smultiple, the SFC compiler needs the explicitbooleanto cast a bare attribute totrue. ThewithDefaultsentry forrangeis dropped becausefalseis not assignable toRange. Vue still casts an absent Boolean prop tofalse, so the runtime default and the documented default stayfalse.New exported helper, next to
GhostSliderValueinghost-slider.ts:ts/** Value emitted by `update:modelValue` for a {@link GhostSlider}. */ export type GhostSliderModelValue<Range extends boolean = false> = Range extends true ? readonly [number, number] : numberThe conditional distributes, so
GhostSliderModelValue<boolean>isGhostSliderValue.Emit.
'update:modelValue': [value: GhostSliderModelValue<Range>]. The one cast this needs, from the composable'sGhostSliderValueto the narrowed payload, sits at the emit call with a comment that names thenormalizeModelinvariant.Inputs stay wide.
modelValueanddefaultValuekeep acceptingGhostSliderValuein both modes (see Q2).Unchanged.
GhostSliderValue,GhostSliderProps,UseGhostSliderOptions(itsonChangestays wide),useGhostSlider, andGhostSliderExposed.Themed wrapper. The themed
GhostSlidertakes the sameRangeparameter. It keeps admitting everything the headless root accepts, asGhostThemedComponentdoes today, but the payload type must come from a generic setup signature and the hand-written construct signature that themedGhostSelectalready uses. A draft prototype that only replaced the export's construct signature accepted<GhostSlider v-model="volume" range>without an error, because the template checker still read the payload from the wrapper's non-genericemitsoption.
| Template | Range | update:modelValue payload |
|---|---|---|
<GhostSlider v-model="volume"> | false | number |
<GhostSlider v-model="bounds" range> | true | readonly [number, number] |
<GhostSlider v-model="value" :range="isRange"> (boolean) | boolean | GhostSliderValue (unchanged) |
Rejected at compile time under strict templates, with volume: Ref<number>:
<GhostSlider v-model="volume" range>: a tuple is not anumber.<GhostSlider v-model="volume" :range="isRange">: the union is not anumber.
A headless prototype of this contract was checked with the repo's vue-tsc (3.3.14) while drafting. The headless slider line of ModelUnions.vue passed unchanged, and every row above behaved as listed. The prototype was not kept.
Backwards compatibility
- A
ref<GhostSliderValue>bound withv-modelstill compiles in every mode: each narrowed payload is assignable to the union, and the input types do not change. - A
ref<readonly [number, number]>withrangestill compiles. - An
@update:model-valuehandler typed(value: GhostSliderValue) => voidstill compiles: a handler that accepts the wider type fits the narrower payload. - Type break.
InstanceType<typeof GhostSlider>no longer resolves for the headless export, since a generic SFC is a function. A consumer who types a template ref that way switches toGhostSliderExposed, the documented ref type. In the repo onlypackages/vue/type-tests/GhostSliderConsumer.tsdoes this. The themed export keeps a construct signature, soInstanceTypekeeps working there. - A mutable
ref<[number, number]>, as theslider/price-filterandslider/audio-mixerexamples use, fails under strict templates before and after this change, because the payload isreadonly. Q3 covers it. - Runtime behavior, DOM, and form submission do not change.
Accessibility
None. Roles, names, values, keyboard behavior, and focus are unchanged.
Implementation acceptance cases
These cases gate the implementation, not this amendment.
- The two slider lines of
ModelUnions.vue(headless and themed) pass without edits,KNOWN_GAPSinscripts/strict-templates-baseline.mjsdrops by two, anddocs/standards/typescript.md#stricttemplatesrecords the new counts. - Under strict templates, for both the headless and the themed export: the three rows in the table compile with matching ref types, a
ref<GhostSliderValue>compiles withrangeomitted, bare, and bound, and both rejected forms fail withTS2322(negative type tests). h(GhostSlider, { 'onUpdate:modelValue': (value: number) => {} })compiles; withrange: truethe handler must accept the tuple.AllComponents.tsstill passes for both exports, so native attributes and listeners stay admitted, andInstanceTypeof the themed export still resolves.- Vue tests lock the invariant the type relies on: a single slider given a tuple
modelValueemits a number, switchingrangeemits nothing, and the next user change after the switch emits the new shape. pnpm manifests:writeandpnpm docs:api:writerun. The manifest and the docs table describerangeand the payload, including thefalsedefault.- Existing slider unit, browser, and type tests pass unchanged, apart from the
InstanceTypeuse inGhostSliderConsumer.ts. - A Changeset for
@ghostvue/vueand@ghostvue/themesnames theInstanceTypebreak and the replacement.
Documentation plan
docs/components/slider.mdexplains thev-modeltype per mode in a sentence and keeps names in the generated tables.- Examples keep
ref<number>for single sliders. Range examples use the ref type Q3 settles on.
Decisions for the maintainer
Resolved 2026-12-04. The maintainer approved the recommended option for each question. The alternatives stay listed as the record of what was considered.
- Q1 — Approach. Recommended: A, a generic SFC keyed on
range, asGhostSelectdoes formultiple. Alternatives: B (cast on a plain SFC) or E (keep the union). - Q2 — Input types. Recommended: keep
modelValueanddefaultValueasGhostSliderValuein both modes, so wide refs keep compiling. Alternative: narrow them too, which would also reject:model-value="[10, 20]"withoutrangebut breaksv-modelon aref<GhostSliderValue>. - Q3 — Tuple payload. Recommended: keep
readonly [number, number], with no runtime change. Alternative: emit a mutable[number, number]and copy the tuple on each emit so it never aliases internal state, as Select's multiple mode does forstring[]. Mutableref<[number, number]>bindings would then compile too. - Q4 — Release. Recommended: one implementation change with the Select amendment, with minor Changesets for both packages, in a release the maintainer picks. Alternative: ship Slider first, because it needs no template change from consumers.