# @rmwc/slider

> RMWC Slider component

Latest version **14.3.5** (published 2024-10-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rmwc/slider
pnpm add @rmwc/slider
yarn add @rmwc/slider
bun add @rmwc/slider
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 14.3.5 |
| Published | 2024-10-24 |
| First published | 2018-09-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 27.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1657 |
| Author | rmwc |
| Maintainers | jamesmfriedman |
| Keywords | rmwc |

## Links

- npm: https://www.npmjs.com/package/@rmwc/slider
- Repository: https://github.com/rmwc/rmwc
- Homepage: https://github.com/rmwc/rmwc/tree/master/packages/slider
- Issues: https://github.com/rmwc/rmwc/issues
- npm.io page: https://npm.io/package/@rmwc/slider

## Dependencies (3)

- [@rmwc/base](https://npm.io/package/@rmwc/base.md) 14.3.5
- [@rmwc/types](https://npm.io/package/@rmwc/types.md) 14.3.5
- [@material/slider](https://npm.io/package/@material/slider.md) ^14.0.0

## Recent versions

- 14.3.5 (latest) — 2024-10-24
- 14.0.2-alpha.7 (next) — 2023-10-30
- 14.3.4 — 2024-09-25
- 14.3.3 — 2024-08-30
- 14.3.2 — 2024-08-19
- 14.3.1 — 2024-07-19
- 14.3.0 — 2024-07-18
- 14.2.9 — 2024-07-03
- 14.2.8 — 2024-07-01
- 14.2.7 — 2024-06-30
- 14.2.6 — 2024-06-28
- 14.2.5 — 2024-06-26
- 14.2.2 — 2024-04-24
- 14.2.1 — 2024-04-17
- 14.2.0 — 2024-04-17
- … 155 more at https://npm.io/package/@rmwc/slider/versions

## README

# Sliders

Sliders let users select from a range of values by moving the slider thumb.

- Module **@rmwc/slider**
- Import styles:
  - Using CSS Loader
    - import '@rmwc/slider/styles';
  - Or include stylesheets
    - **'@material/slider/dist/mdc.slider.css'**
- MDC Docs: [https://material.io/develop/web/components/input-controls/sliders/](https://material.io/develop/web/components/input-controls/sliders/)

Sliders can be both uncontrolled and controlled. When creating a controlled `Slider`, you should be listening to the `onInput` event and use `evt.detail.value` to set your new value.

Sliders will automatically layout themselves on window resize. If you need to manually trigger a layout because the sliders container size changed, the simplest way is to trigger a resize event `window.dispatchEvent(new Event('resize'));`.

**Known Issue** `material-components-web` uses pointer events internally. If you are using something below React 16.4, you will see unknown attribute errors, however the slider should still work.

```jsx
<Slider
  onInput={(evt) => console.log(evt)}
  onChange={(evt) => console.log(evt)}
/>
```

```jsx
function Example() {
  const [value, setValue] = React.useState(50);
  // onInput is required and will fire continuously.
  // onChange is optional and fires at the end of the interaction
  return (
    <Slider
      value={value}
      onChange={(evt) => setValue(evt.detail.value)}
      onInput={(evt) => setValue(evt.detail.value)}
      discrete
      step={10}
    />
  );
}
```

```jsx
<Slider discrete min={0} max={200} step={10} />
```

```jsx
<Slider discrete displayMarkers step={10} />
```

```jsx
function Example() {
  const [value, setValue] = React.useState(80);
  const [startValue, setStartValue] = React.useState(20);
  return (
    <Slider
      range
      discrete
      valueStart={startValue}
      value={value}
      onChange={(evt) => setValue(evt.detail.value)}
      onChangeValueStart={(evt) => setStartValue(evt.detail.value)}
    ></Slider>
  );
}
```

## Slider
A Slider component.

### Props

| Name | Type | Description |
|------|------|-------------|
| `disabled` | `boolean` | Disables the control. |
| `discrete` | `boolean` | Displays the exact value of the Slider on the knob. |
| `displayMarkers` | `boolean` | Displays the individual step markers on the Slider track. |
| `foundationRef` | `Ref<MDCSliderFoundation<>>` | Advanced: A reference to the MDCFoundation. |
| `max` | `string \| number` | The maximum value of the Slider. |
| `min` | `string \| number` | The minimum value of the Slider. |
| `minRange` | `string \| number` | The minimum gap between two thumbs for range sliders. |
| `onChange` | `(evt: SliderOnChangeEventT) => void` | A callback that fires when the Slider stops sliding which takes an event with event.detail.value set to the Slider's value. evt.detail = { value: number;} |
| `onChangeValueStart` | `(evt: SliderOnChangeEventT) => void` | A callback that fires when the Slider stops sliding which takes an event with event.detail.value set to the Slider's valueStart. evt.detail = { value: number;} |
| `onInput` | `(evt: SliderOnInputEventT) => void` | A callback that fires continuously while the Slider is sliding that takes an event with event.detail.value set to the Slider's value. evt.detail = { value: number;} |
| `onInputValueStart` | `(evt: SliderOnInputEventT) => void` | A callback that fires continuously while the Slider is sliding that takes an event with event.detail.value set to the Slider's valueStart. evt.detail = { value: number;} |
| `range` | `boolean` | Makes the slider a range slider. |
| `step` | `string \| number` | A step to quantize values by. |
| `value` | `string \| number` | The value of the Slider. When Slider is of type range, value becomes the end value. |
| `valueStart` | `number` | The start value of the Slider range. |

---
_Source: https://npm.io/package/@rmwc/slider · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
