Histogram Range

Dual-thumb range slider combined with a distribution histogram bar chart.

@drift-ui/histogram-rangeRegistry JSONOpen in v0
$80 – $30026 of 44 results
26 of 44 results in selected range

Keyboard

←→
Adjust the focused thumb by step
↑↓
Adjust the focused thumb by step
PageUpPageDown
Adjust the focused thumb by larger step
HomeEnd
Set the focused thumb to min or max
On this page

Installation

The CLI also installs the npm packages and registry items it builds on, and reads the style in your components.json to pick the Base UI or Radix build.

Usage

histogram-range-usage.tsx
"use client"

import { useState } from "react"
import { HistogramRange } from "@/components/ui/histogram-range"

const prices = [25, 45, 60, 75, 80, 110, 120, 150, 180, 220, 260, 310, 450]

export function PriceFilter() {
  const [range, setRange] = useState<[number, number]>([50, 200])

  return (
    <HistogramRange
      data={prices}
      min={0}
      max={500}
      value={range}
      onValueChange={setRange}
      formatValue={(n) => `$${n}`}
      minThumbLabel="Minimum price"
      maxThumbLabel="Maximum price"
      showValues
      showCount
    />
  )
}

Examples

Basic price range

A dual-thumb range filter with dollar formatting and active result count.

$50 – $2508 of 13 results
8 of 13 results in selected range

Custom units and styling

File size filtering with megabytes formatting and chart color tokens.

10 MB – 100 MB8 / 14 files
8 / 14 files

API reference

HistogramRange

A dual-thumb range slider sitting below a distribution histogram bar chart. Highlights values in the selected range and mutes values outside.

Prop
datanumber[]Raw numeric dataset to distribute across histogram bins.
minnumberLower bound of the range. Defaults to min value in data, or 0.
maxnumberUpper bound of the range. Defaults to max value in data, or 100.
stepnumberDefault1Step increment of the slider thumbs.
minStepsBetweenThumbsnumberDefault0Minimum number of steps required between the two thumbs.
value[number, number]Controlled selected range.
defaultValue[number, number]Default[min, max]Initial value when uncontrolled.
onValueChange(value: [number, number]) => voidCalled when the range changes during dragging or keyboard input.
onValueCommit(value: [number, number]) => voidCalled when pointer drag or keyboard interaction finishes.
binsnumberDefault24Number of discrete histogram buckets.
formatValue(value: number) => stringFormats values for display and thumb aria-valuetext.
minThumbLabelstringDefault"Minimum"Accessible aria-label for the lower thumb.
maxThumbLabelstringDefault"Maximum"Accessible aria-label for the upper thumb.
showValuesbooleanDefaultfalseWhether to render current range values above the chart.
showCountbooleanDefaultfalseWhether to render active item count above the chart.
renderCount(selectedCount: number, totalCount: number) => React.ReactNodeCustom renderer for result count summary and live region.
barHeightnumber | stringDefault64Height of the histogram chart area.
barColorstringTailwind class for active bars inside the range (defaults to bg-primary).
mutedBarColorstringTailwind class for inactive bars outside the range (defaults to bg-muted-foreground/20).
disabledbooleanDefaultfalseWhether the slider thumbs are disabled.

Other props go to the <div>.

buildHistogramBuckets

buildHistogramBuckets(options: BuildHistogramBucketsOptions): BuildHistogramBucketsResult

Pure logic helper in @/lib/histogram-range that buckets numeric data, normalizes bar heights, and calculates inRange statuses.

Source

components/ui/histogram-range.tsx