Skip to content

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:modelValue type keyed on range is 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 stable data-part children for theming.
  • It does not own labeling primitives (GhostField, GHO-71). Consumers supply names through aria-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 / step are 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:

PropTypeDefaultContract
modelValuenumber | [number, number]omittedControlled value. Single-thumb mode uses a number; range mode uses a readonly two-tuple [minThumb, maxThumb]. Omitted is uncontrolled.
defaultValuesame as modelValuemin or [min, max] in range modeInitial value when modelValue is omitted. Captured at mount for reset; later prop changes ignored.
minnumber0Lower bound. Must be finite and <= max after coercion.
maxnumber100Upper bound. Must be finite and >= min.
stepnumber1Snap increment. Must be finite and > 0; invalid values fall back to 1.
rangebooleanfalseWhen true, two thumbs select an interval; modelValue / defaultValue use tuples.
orientation'horizontal' | 'vertical''horizontal'Maps to aria-orientation and keyboard axis.
disabledbooleanfalseNative disabled: thumbs not operable, not focusable, hidden inputs not submitted.
namestringomittedForm field name for the primary (or only) value. Hidden type="hidden".
nameMaxstringomittedIn range mode, form field name for the high thumb. Ignored when range is false.
formstringomittedAssociates hidden inputs with an external form id.
valueTextstringomittedOptional 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:

PropTypeDefaultContract
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 modelValue is uncontrolled. Local state starts at defaultValue (single: min; range: [min, max] unless defaultValue is provided).
  • A defined modelValue is controlled. Writes emit update:modelValue and do not update local state when controlled.
  • Assignment is skipped when the snapped value is unchanged (Object.is for numbers; tuple compared by element with Object.is).
  • Switching controlled/uncontrolled at runtime logs GHOST001 in development.
  • Form reset restores the mount-captured defaultValue, using nextTick before reconciling hidden input DOM when controlled, matching GhostCheckbox / 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: root HTMLElement | null
  • value: current number or readonly tuple (mirrors the model)
  • focus(options?): focuses the first enabled thumb
  • blur(): 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-slider with data-part="root". No role on the root.
  • Each thumb: div with role="slider", tabindex="0" when enabled, aria-valuemin, aria-valuemax, aria-valuenow, optional aria-valuetext, optional aria-orientation when 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):

KeyHorizontal LTRHorizontal RTLVertical
Arrow toward maxArrowRightArrowLeftArrowUp
Arrow toward minArrowLeftArrowRightArrowDown
Large step toward maxPageUpPageUpPageUp
Large step toward minPageDownPageDownPageDown
MinimumHomeHomeHome
MaximumEndEndEnd

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:

PartDescription
rootPositioning context and attribute fallthrough host
trackFull span of the axis
rangeSelected interval fill (range mode or single fill from min)
thumbDraggable 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 ​

  • useControllableState for the model.
  • useNativeFormReset + afterNativeFormReset policy from form-reset.ts.
  • Does not use useRovingFocus; slider arrows adjust values, not focus.
  • useGhostId is 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 reactive dir. Assertions use bounding boxes and aria-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: GhostSliderProps fallthrough and v-model types.
  • Themed integration: element ref 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 GhostSlider with 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:

text
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 ​

OptionStrict v-model on ref<number>Cost and risk
A. Generic SFC keyed on range (recommended)CompilesSame 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 signatureCompilesKeeps 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 componentCompilesTwo 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")CompilesUnsound. 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 refFailsNo change, but the strict-templates gap stays.

Proposed contract ​

  • Headless SFC. GhostSlider.vue becomes <script setup lang="ts" generic="Range extends boolean = false">. The prop is declared range?: Range & boolean: as with Select's multiple, the SFC compiler needs the explicit boolean to cast a bare attribute to true. The withDefaults entry for range is dropped because false is not assignable to Range. Vue still casts an absent Boolean prop to false, so the runtime default and the documented default stay false.

  • New exported helper, next to GhostSliderValue in ghost-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] : number

    The conditional distributes, so GhostSliderModelValue<boolean> is GhostSliderValue.

  • Emit. 'update:modelValue': [value: GhostSliderModelValue<Range>]. The one cast this needs, from the composable's GhostSliderValue to the narrowed payload, sits at the emit call with a comment that names the normalizeModel invariant.

  • Inputs stay wide. modelValue and defaultValue keep accepting GhostSliderValue in both modes (see Q2).

  • Unchanged. GhostSliderValue, GhostSliderProps, UseGhostSliderOptions (its onChange stays wide), useGhostSlider, and GhostSliderExposed.

  • Themed wrapper. The themed GhostSlider takes the same Range parameter. It keeps admitting everything the headless root accepts, as GhostThemedComponent does today, but the payload type must come from a generic setup signature and the hand-written construct signature that themed GhostSelect already 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-generic emits option.

TemplateRangeupdate:modelValue payload
<GhostSlider v-model="volume">falsenumber
<GhostSlider v-model="bounds" range>truereadonly [number, number]
<GhostSlider v-model="value" :range="isRange"> (boolean)booleanGhostSliderValue (unchanged)

Rejected at compile time under strict templates, with volume: Ref<number>:

  • <GhostSlider v-model="volume" range>: a tuple is not a number.
  • <GhostSlider v-model="volume" :range="isRange">: the union is not a number.

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 with v-model still compiles in every mode: each narrowed payload is assignable to the union, and the input types do not change.
  • A ref<readonly [number, number]> with range still compiles.
  • An @update:model-value handler typed (value: GhostSliderValue) => void still 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 to GhostSliderExposed, the documented ref type. In the repo only packages/vue/type-tests/GhostSliderConsumer.ts does this. The themed export keeps a construct signature, so InstanceType keeps working there.
  • A mutable ref<[number, number]>, as the slider/price-filter and slider/audio-mixer examples use, fails under strict templates before and after this change, because the payload is readonly. 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.

  1. The two slider lines of ModelUnions.vue (headless and themed) pass without edits, KNOWN_GAPS in scripts/strict-templates-baseline.mjs drops by two, and docs/standards/typescript.md#stricttemplates records the new counts.
  2. 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 with range omitted, bare, and bound, and both rejected forms fail with TS2322 (negative type tests).
  3. h(GhostSlider, { 'onUpdate:modelValue': (value: number) => {} }) compiles; with range: true the handler must accept the tuple.
  4. AllComponents.ts still passes for both exports, so native attributes and listeners stay admitted, and InstanceType of the themed export still resolves.
  5. Vue tests lock the invariant the type relies on: a single slider given a tuple modelValue emits a number, switching range emits nothing, and the next user change after the switch emits the new shape.
  6. pnpm manifests:write and pnpm docs:api:write run. The manifest and the docs table describe range and the payload, including the false default.
  7. Existing slider unit, browser, and type tests pass unchanged, apart from the InstanceType use in GhostSliderConsumer.ts.
  8. A Changeset for @ghostvue/vue and @ghostvue/themes names the InstanceType break and the replacement.

Documentation plan ​

  • docs/components/slider.md explains the v-model type 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.

  1. Q1 — Approach. Recommended: A, a generic SFC keyed on range, as GhostSelect does for multiple. Alternatives: B (cast on a plain SFC) or E (keep the union).
  2. Q2 — Input types. Recommended: keep modelValue and defaultValue as GhostSliderValue in both modes, so wide refs keep compiling. Alternative: narrow them too, which would also reject :model-value="[10, 20]" without range but breaks v-model on a ref<GhostSliderValue>.
  3. 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 for string[]. Mutable ref<[number, number]> bindings would then compile too.
  4. 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.