Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Range with Constraints Slider for Vue

A Constrained Range slider from 0 to 100, opening at 20 and 60, with the thumbs kept at least 10 apart.

UI library: Ark UI

Constrained Range is on the left and 20 - 60 is on the right. Under the track, a note reads Minimum gap: 10.

Use it for a booking window or any span that must not collapse. A Date Picker is clearer when each end is a date. In Vue, Ark UI does not write the gap note.

Preview

Preview width

Installation

MCP · Pro
Make your AI a shadcn expert
Your agent installs components, builds pages and restyles your app from one prompt, in Claude Code, Cursor or VS Code.
Part of Pro

Anatomy

Slider anatomy: root, label, value, track, range, thumb

Usage

<div class="flex w-full max-w-md flex-col gap-2">
  <div class="flex items-center justify-between">
    <Label>Constrained Range</Label>
    <span class="text-muted-foreground text-sm tabular-nums">
      {{ value[0] }} - {{ value[1] }}
    </span>
  </div>
  <Slider
    :aria-label='["Range start", "Range end"]'
    :max="100"
    :min="0"
    :minStepsBetweenThumbs="MIN_GAP"
    @value-change="handleValueChange"
    :value="value"
  />
  <p class="text-muted-foreground text-xs">Minimum gap: {{ MIN_GAP }}</p>
</div>

FAQ

How is the gap enforced?

MIN_GAP is 10, and the slider will not let the thumbs come closer than that. It is passed as minStepsBetweenThumbs. With step 1, that is a gap of 10.

How does the readout follow the thumb?

The value lives in state, starting at [20, 60], and goes back to the slider as value. The two numbers beside the label print them. The Vue file binds :value and listens to @value-change, which receives details.value.

What is the text under the track?

Minimum gap: 10, printed from the same MIN_GAP, so the note and the rule never disagree.

What range does it cover?

0 to 100 in steps of 1. min and max set the ends.

How are the thumbs named?

Constrained Range is a visible Label. On Ark UI, aria-label names each thumb: Range start and Range end.

Can I move it from the keyboard?

Yes. The thumb takes focus with Tab. The arrow keys move it by one step, Page Up and Page Down by a larger step, and Home and End jump to the ends.

API Reference

Label

No extra props in this demo. The rest is on the Label page.

Slider

Sets aria-label="[Range start, Range end]", max="100", min="0", minStepsBetweenThumbs="MIN_GAP", value-change="handleValueChange" and value="value". The rest is on the Slider page.