# Slider

A **Slider** provides a visual indication of adjustable content, where the user can increase or decrease the value by moving the slider thumb along a horizontal track.

## Usage

![Slider](<../images/slider.png>)

Sliders allow users to view and select a value from the range along a horizontal track. They’re ideal for adjusting settings such as volume and brightness where accuracy is not of highest importance.

The buttons can be used to make small adjustments in either direction, while the slider thumb can be used for larger adjustments.

Changes made with sliders take effect immediately, allowing users to make slider adjustments with direct feedback.

### When to use

- Use it for making selections from a range of values.
- Use it when the range is more important than precision.

### Best practices

- Use a regular value input, if a user needs to enter a precise number.
- Sliders shouldn’t be used to adjust settings with any delay in providing user feedback.

## Design

### Elements

![Slider Elements](<../images/slider-elements.png>)

> 1. \+/- Button, 2. Thumb, 3. Thumb icon (Optional), 4. Track, 5. Range values (Optional)

### Slider variations

![Slider variations](<../images/slider-variations.png>)

### Thumb interaction states

The thumb can optionally contain an icon.

![Slider thumb states](<../images/slider-thumb-states.png>)

## Code

### Usage

```
import { SiSliderComponent } from '@siemens/element-ng/slider';

@Component({
  imports: [SiSliderComponent, ...]
})
```

#### Example

##### Default slider

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component, inject } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { SiSliderComponent } from '@siemens/element-ng/slider';
import { LOG_EVENT } from '@siemens/live-preview';

@Component({
  selector: 'app-sample',
  imports: [SiSliderComponent, FormsModule],
  templateUrl: './si-slider.html',
  host: { class: 'p-5' }
})
export class SampleComponent {
  slidingValue = 50;
  logEvent = inject(LOG_EVENT);
  disabled = false;
}
```

Template:

```html
<form class="container-fluid">
  <div class="mb-6 row">
    <span id="slider-label" class="col-sm-2 col-form-label">Slide</span>
    <div class="col-sm-10">
      <si-slider
        minLabel="0 %"
        maxLabel="100 %"
        labelledby="slider-label"
        [disabled]="disabled"
        [min]="0"
        [max]="100"
        [step]="10"
        [(value)]="slidingValue"
        (valueChange)="logEvent($event)"
      />
    </div>
  </div>
  <div class="mb-6 row">
    <label for="number" class="col-sm-2 col-form-label">Write</label>
    <div class="col-sm-10">
      <input
        type="number"
        class="form-control"
        id="number"
        name="number"
        placeholder="0-100"
        [min]="0"
        [max]="100"
        [step]="10"
        [(ngModel)]="slidingValue"
      />
    </div>
  </div>
  <div class="mb-6 row">
    <div class="offset-sm-2 col-sm-10">
      <label class="form-check mb-2">
        <input type="checkbox" class="form-check-input" name="disabled" [(ngModel)]="disabled" />
        <span class="form-check-label">Disabled</span>
      </label>
    </div>
  </div>
</form>
```

##### with icon

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component, inject } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { SiSliderComponent } from '@siemens/element-ng/slider';
import { LOG_EVENT } from '@siemens/live-preview';

@Component({
  selector: 'app-sample',
  imports: [SiSliderComponent, FormsModule],
  templateUrl: './si-slider-icon.html',
  host: { class: 'p-5' }
})
export class SampleComponent {
  logEvent = inject(LOG_EVENT);
  slidingValue = 85;
  disabled = false;
}
```

Template:

```html
<form class="container-fluid">
  <div class="mb-6 row">
    <label for="number" class="col-sm-2 col-form-label">Slide</label>
    <div class="col-sm-10">
      <si-slider
        thumbIcon="element-temperature"
        [disabled]="disabled"
        [min]="0"
        [max]="100"
        [step]="10"
        [(value)]="slidingValue"
        (valueChange)="logEvent($event)"
      />
    </div>
  </div>
  <div class="mb-6 row">
    <label for="number" class="col-sm-2 col-form-label">Write</label>
    <div class="col-sm-10">
      <input
        type="number"
        class="form-control"
        id="number"
        name="number"
        placeholder="0-100"
        [min]="0"
        [max]="100"
        [step]="10"
        [(ngModel)]="slidingValue"
      />
    </div>
  </div>
  <div class="mb-6 row">
    <div class="offset-sm-2 col-sm-10">
      <label class="form-check mb-2">
        <input type="checkbox" class="form-check-input" name="disabled" [(ngModel)]="disabled" />
        <span class="form-check-label">Disabled</span>
      </label>
    </div>
  </div>
</form>
```

### [SiSliderComponent](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L50-L344>)

**Kind:** component

**Selector:** `si-slider`

```
import { SiSliderComponent } from '@siemens/element-ng/slider';
```

```
component SiSliderComponent implements ControlValueAccessor, SiFormItemControl
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [decrementLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L120-L120>) | `TranslatableString` | `` $localize`:@@SI_SLIDER.DECREMENT:Decrement` `` | Text for aria-label of decrement. Needed for a11y. |
| [disabled](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L141-L141>) | `boolean` | `false` |  |
| [errormessageId](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L165-L165>) | `string` | `` `${this.id()}-errormessage` `` | This ID will be bound to the `aria-describedby` attribute of the slider. Use this to reference the element containing the error message(s) for the slider. It will be picked by the [SiFormItemComponent](<../../../api/siemens/element-ng/components/SiFormItemComponent/index.html#SiFormItemComponent>) if the slider is used inside a form item.<br><br>Implements [SiFormItemControl](<index.html#t:SiFormItemControl>) |
| [id](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L63-L63>) | `string` | `` `__si-slider-${SiSliderComponent.idCounter++}` `` | The actual id of the control that should be used in the `for` attribute of a label.<br><br>Implements [SiFormItemControl](<index.html#t:SiFormItemControl>) |
| [incrementLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L111-L111>) | `TranslatableString` | `` $localize`:@@SI_SLIDER.INCREMENT:Increment` `` | Text for aria-label of increment. Needed for a11y. |
| [labelledby](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L137-L137>) | `string` | `` `${this.id()}-label` `` | ID that should be assigned to the label element inside the [SiFormItemComponent](<../../../api/siemens/element-ng/components/SiFormItemComponent/index.html#SiFormItemComponent>).<br><br>If the target control is not of type input, select or button, it cannot be referenced by a label. Instead, aria-labelledby must be used to create a reference to a label. In such a case, an implementation of [SiFormItemControl](<index.html#t:SiFormItemControl>) must provide the id of the label in [labelledby](<index.html#SiSliderComponent.labelledby>). [SiFormItemComponent](<../../../api/siemens/element-ng/components/SiFormItemComponent/index.html#SiFormItemComponent>) will apply the id to the label so that it can be used inside the control to reference it in the aria-labelledby attribute.<br><br>Implements [SiFormItemControl](<index.html#t:SiFormItemControl>) |
| [max](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L80-L80>) | `number` | `100` | Maximum of slider range. |
| [maxLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L92-L92>) | `string` | `''` | Label to describe maximum of slider range. |
| [min](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L74-L74>) | `number` | `0` | Minimum of slider range. |
| [minLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L86-L86>) | `string` | `''` | Label to describe minimum of slider range. |
| [sliderLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L129-L129>) | `TranslatableString` | `` $localize`:@@SI_SLIDER.LABEL:Value` `` | Text for aria-label of slider. Needed for a11y |
| [step](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L98-L98>) | `number` | `1` | Interval to step through the slider. |
| [thumbIcon](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L102-L102>) | `string \| undefined` |  | Icon to use as the slider thumb. |
| [value](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L68-L68>) | `number \| undefined` |  | Current value of slider. |

#### Output Properties

| Name | Type | Description |
| --- | --- | --- |
| [valueChange](<https://github.com/siemens/element/blob/main/projects/element-ng/slider/si-slider.component.ts#L68-L68>) | `number \| undefined` | Current value of slider. |

### Types Documentation

### [TranslatableString](<https://github.com/siemens/element/blob/main/projects/element-translate-ng/translate-types/global.types.ts#L18-L18>)

**Kind:** type alias

```
import type { TranslatableString } from '@siemens/element-translate-ng/translate-types';
```

Represents a translatable string. This can either be a translation key, e.g. `ACTIONS.EDIT` that will be automatically translated when displayed on the UI or a pre-translated string, e.g. `Edit`. Equivalent to a normal string in usage and functionality.

```
type TranslatableString = string & Translatable
```

### [SiFormItemControl](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-item.control.ts#L14-L38>)

**Kind:** interface

```
import type { SiFormItemControl } from '@siemens/element-ng/form';
```

Common interface for form item controls. Controls that should be connected to [SiFormItemComponent](<../../../api/siemens/element-ng/components/SiFormItemComponent/index.html#SiFormItemComponent>) must implement this interface and must be provided using the [SI\_FORM\_ITEM\_CONTROL](<../../../api/siemens/element-ng/types/SI_FORM_ITEM_CONTROL/index.html#t:SI_FORM_ITEM_CONTROL>) token.

```
interface SiFormItemControl
```

#### Properties

| Name | Type | Description |
| --- | --- | --- |
| [errormessageId](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-item.control.ts#L34-L34>) (readonly) | `string \| Signal<string>` | Generated ID that the [SiFormItemComponent](<../../../api/siemens/element-ng/components/SiFormItemComponent/index.html#SiFormItemComponent>) will assign to the element containing the error messages. Implementations of [SiFormItemControl](<index.html#t:SiFormItemControl>) must generate this ID and assign it to the `aria-describedby` attribute of their focusable elements. |
| [id](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-item.control.ts#L16-L16>) (optional, readonly) | `string \| Signal<string \| undefined>` | The actual id of the control that should be used in the `for` attribute of a label. |
| [isFormCheck](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-item.control.ts#L37-L37>) (optional, readonly) | `boolean` | If the control is meant to be used a checkbox. This affects the label positioning. |
| [labelledby](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-item.control.ts#L27-L27>) (optional, readonly) | `string \| Signal<string \| undefined> \| null` | ID that should be assigned to the label element inside the [SiFormItemComponent](<../../../api/siemens/element-ng/components/SiFormItemComponent/index.html#SiFormItemComponent>).<br><br>If the target control is not of type input, select or button, it cannot be referenced by a label. Instead, aria-labelledby must be used to create a reference to a label. In such a case, an implementation of [SiFormItemControl](<index.html#t:SiFormItemControl>) must provide the id of the label in [labelledby](<index.html#t:SiFormItemControl.labelledby>). [SiFormItemComponent](<../../../api/siemens/element-ng/components/SiFormItemComponent/index.html#SiFormItemComponent>) will apply the id to the label so that it can be used inside the control to reference it in the aria-labelledby attribute. |
