# Slider — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/slider

Category: Input controls

Displays a styled slider for numeric input, supporting single or multiple thumbs, highlighting ranges, and optional 'Set Null'.

Public component import: `Slider`

Public manager import: `create_slider_manager`

## Usage

```svelte
<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { Slider, create_slider_manager } from "sveltekit-ui"

  const manager = create_slider_manager({
    label: "Volume",
    name: "volume",
    val: 50,
    min: 0,
    max: 100,
    step: 5,
  })
</script>

<Slider {manager} />
<p>Volume: {manager.val}%</p>
```

## Configuration

### `val`

- type: number or number[]
- default: 0
- description: Current value(s). If an array is provided, multiple thumbs appear.

### `min`

- type: number
- default: 0
- description: Minimum value range.

### `max`

- type: number
- default: 2
- description: Maximum value range.

### `step`

- type: number
- default: 0.01
- description: Value increment steps.

### `on_change`

- type: function
- default: null
- description: Called with new value(s) when changed (pointer move or arrow key).

### `on_down`

- type: function
- default: null
- description: Called with new value when pointer is pressed.

### `on_up`

- type: function
- default: null
- description: Called with final value(s) when pointer is released.

### `label`

- type: string or null
- default: null
- description: Label text displayed above the slider.

### `name`

- type: string
- default: slider
- description: Name attribute for potential form usage.

### `label_font_size`

- type: number
- default: 1.2
- description: Size in rem for label text.

### `is_required`

- type: boolean
- default: false
- description: Whether the field is required for form submission.

### `is_read_only`

- type: boolean
- default: false
- description: If true, the slider can't be changed.

### `font_size`

- type: number
- default: 1
- description: Base text size for the slider thumb.

### `is_disabled`

- type: boolean
- default: false
- description: If true, slider is disabled. If val is null and is_nullable is false, defaults to true.

### `is_nullable`

- type: boolean
- default: false
- description: If true, a 'Set Null' / 'Select Value' button toggles val between null and min.

### `color`

- type: CSS color
- default: var(--primary-t)
- description: Color used for highlight track background and thumb details.

### `is_short`

- type: boolean
- default: false
- description: If true, uses a more compact thumb design.

### `is_show_text`

- type: boolean
- default: true
- description: If false, hides numeric text on thumb.

### `ml`

- type: number
- default: 0
- description: Margin-left in rem.

### `mr`

- type: number
- default: 0
- description: Margin-right in rem.

### `mt`

- type: number
- default: 0
- description: Margin-top in rem.

### `mb`

- type: number
- default: 0
- description: Margin-bottom in rem.

### `highlight_range_start_percent`

- type: number
- default: 0
- description: Optional highlight range start in percent (0-100).

### `highlight_range_end_percent`

- type: number
- default: 0
- description: Optional highlight range end in percent (0-100).

## Methods

### `init()`

- description: Sets initial min, max, step, etc. Called once with the config. Also sets up thumbs from val.

### `set_val()`

- description: Programmatically updates the slider's val (and thumbs).

### `handle_pointer_down()`

- description: Begins tracking pointer for a slider thumb drag.

### `handle_pointer_move()`

- description: Moves the closest thumb to the pointer's position.

### `handle_pointer_up()`

- description: Finishes the drag, calls on_up with final value(s).

### `handle_thumb_keydown()`

- description: Moves the thumb left/right by step when arrow keys pressed.

### `set_loading_i()`

- description: Sets the thumb index to display loading state.

### `set_error_i()`

- description: Sets the thumb index to display error state.

### `set_min()`

- description: Updates the slider's min bound.

### `set_max()`

- description: Updates the slider's max bound.

### `set_step()`

- description: Updates the slider's step value.

## Returned state

### `val`

- type: number or number[]
- description: Current value(s) after pointer move/arrow key changes.

### `working_val`

- type: array
- description: Internal slider thumb(s) values.

### `loading_i`

- type: number or null
- description: Thumb index that is loading, if any. Setting triggers loading state for that thumb.

### `error_i`

- type: number or null
- description: Thumb index that has an error, if any.

### `toggle_null_button_manager`

- type: object
- description: Button manager for toggling null if is_nullable is true.
