my/ui

Command Palette

Search for a command to run...

All components

Dual Range Input Slider

sliders

Origin UI component.

responsive · 600px

Install

Same command in any shadcn project — React (Vite/CRA), Next.js, Remix, Astro, and more:

$npx shadcn@latest add https://your-domain/r/comp-258.json

Usage

import Cmp from "@/registry/origin-ui/comp-258";

export default function Demo() {
  return <Cmp />;
}

Component source

"use client";

import { useSliderWithInput } from "@/registry/origin-ui/use-slider-with-input";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Slider } from "@/components/ui/slider";

export default function Component() {
  const minValue = 0;
  const maxValue = 200;
  const initialValue = [50, 150];

  const {
    sliderValue,
    inputValues,
    validateAndUpdateValue,
    handleInputChange,
    handleSliderChange,
  } = useSliderWithInput({ initialValue, maxValue, minValue });

  return (
    <div className="*:not-first:mt-3">
      <Label>Dual range slider with input</Label>
      <div className="flex items-center gap-4">
        <Input
          aria-label="Enter minimum value"
          className="h-8 w-12 px-2 py-1"
          inputMode="decimal"
          onBlur={() => validateAndUpdateValue(inputValues[0], 0)}
          onChange={(e) => handleInputChange(e, 0)}
          onKeyDown={(e) => {
            if (e.key === "Enter") {
              validateAndUpdateValue(inputValues[0], 0);
            }
          }}
          type="text"
          value={inputValues[0]}
        />
        <Slider
          aria-label="Dual range slider with input"
          className="grow"
          max={maxValue}
          min={minValue}
          onValueChange={handleSliderChange}
          value={sliderValue}
        />
        <Input
          aria-label="Enter maximum value"
          className="h-8 w-12 px-2 py-1"
          inputMode="decimal"
          onBlur={() => validateAndUpdateValue(inputValues[1], 1)}
          onChange={(e) => handleInputChange(e, 1)}
          onKeyDown={(e) => {
            if (e.key === "Enter") {
              validateAndUpdateValue(inputValues[1], 1);
            }
          }}
          type="text"
          value={inputValues[1]}
        />
      </div>
    </div>
  );
}

Source: Origin UI