# Slider

SvSlider: a filter block - a dual-thumb price range plus single sliders for rating and distance, with ticks and live formatted readouts.

Uses `@svgrid/grid` (MIT). Category: Range & Feedback. Live demo: https://svgrid.com/demos/318-slider/

Install: `npm i @svgrid/grid` (Svelte 5).

## About this example

SvSlider in Svelte 5 as a filter block: a dual-thumb price range with range, min, max and step, ticks and labels on every mark, a formatValue function that prints dollar amounts, plus single sliders for rating and distance with live formatted readouts. Keyboard accessible and themed from the tokens.

SvSlider - a production filter block: a dual-thumb price range plus single sliders for rating and distance, with live formatted readouts. Copy-paste ready.

## Imports, features and API used

- Imports: `@svgrid/grid`

## Frequently asked questions

### How do I get two thumbs?

Add range. The value becomes a [min, max] tuple, both thumbs respect step, and they cannot cross.

### How do I format the readout?

Pass formatValue, a function from number to string, which the slider uses for the value bubble and, with labels='all', for the tick labels too.

### Can the slider be vertical?

Yes. orientation='vertical' turns the track vertical with the same keyboard model, which suits volume and level controls.

## Related documentation

- [SvSlider](https://svgrid.com/docs/help/ui-components/sv-slider.md)

## Related articles

- [Copy a Cell Range to the Clipboard in SvGrid](https://svgrid.com/blog/copy-cell-range-to-clipboard/) - How SvGrid copies selected cell ranges as tab-separated values that paste cleanly into Excel and Google Sheets, plus headers, programmatic copy, and format control.
- [Spreadsheet-Style Cell Range Selection in SvGrid](https://svgrid.com/blog/cell-range-selection/) - How to enable drag-to-select cell ranges, read live selection state, and build a status-bar footer that sums and averages the selected values.

## Source code (318-slider.svelte)

```svelte
<script lang="ts">
  /**
   * SvSlider - a production filter block: a dual-thumb price range plus single
   * sliders for rating and distance, with live formatted readouts. Copy-paste
   * ready.
   */
  import { SvSlider } from '@svgrid/grid'

  let price = $state<[number, number]>([200, 800])
  let minRating = $state(4)
  let distance = $state(10)
  const money = (n: number) => `$${n.toLocaleString()}`
</script>

<div class="wrap">
  <header>
    <h2>Slider</h2>
    <p>Single or dual-thumb range (WAI-ARIA slider) with steps, ticks and keyboard - price filters, thresholds, settings.</p>
  </header>

  <div class="panel">
    <div class="filter">
      <div class="lbl"><span>Price range</span><strong>{money(price[0])} - {money(price[1])}</strong></div>
      <SvSlider value={price} range min={0} max={1000} step={50} ticks={5} labels="all" formatValue={(v) => `$${v}`} onChange={(v) => (price = v)} />
    </div>

    <div class="filter">
      <div class="lbl"><span>Minimum rating</span><strong>{minRating}+ stars</strong></div>
      <SvSlider value={minRating} min={1} max={5} step={1} ticks={5} labels="endpoints" showValue onChange={(v) => (minRating = v)} />
    </div>

    <div class="filter">
      <div class="lbl"><span>Within</span><strong>{distance} km</strong></div>
      <SvSlider value={distance} min={1} max={50} formatValue={(v) => `${v} km`} onChange={(v) => (distance = v)} />
    </div>
  </div>
</div>

<style>
  .wrap { padding: 20px; max-width: 460px; display: flex; flex-direction: column; gap: 16px; }
  header h2 { margin: 0 0 4px; font-size: 20px; font-weight: 700; }
  header p { margin: 0; color: var(--sg-muted, #64748b); font-size: 13.5px; line-height: 1.5; }
  .panel { display: flex; flex-direction: column; gap: 22px; padding: 18px; border: 1px solid var(--sg-border, #e2e8f0); border-radius: 12px; }
  .filter { display: flex; flex-direction: column; gap: 4px; }
  .lbl { display: flex; justify-content: space-between; font-size: 13px; }
  .lbl span { color: var(--sg-muted, #64748b); font-weight: 600; }
</style>
```

[View this example on GitHub](https://github.com/sv-grid/sv-grid/blob/main/examples/src/demos/318-slider.svelte)
