Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Slider examples · Range

Range with Constraints Slider for React

A two-thumb slider whose thumbs always stay at least 10 apart.

Framework
UI library

Some ranges must never collapse. The two thumbs here keep a gap of at least 10, so the range is never shorter than that. Use it for booking windows or any span with a minimum length.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

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 minStepsBetweenValues. 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. onValueChange receives the new value, and the handler stores it as an array.

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 Base UI, aria-label names the slider Range.

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.