- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input Group
- Input OTP
- Input
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner (Toast)
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
- Trace
Slider
An input where the user selects a value from within a given range.
import { Component, signal } from '@angular/core';
import { HlmSliderImports } from '@spartan-ng/helm/slider';
@Component({
selector: 'spartan-slider-preview',
imports: [HlmSliderImports],
styles: `
:host {
display: block;
width: 60%;
}
`,
template: `
<hlm-slider [(value)]="value" />
`,
})
export class SliderPreview {
public readonly value = signal([75]);
}Installation
ng g @spartan-ng/cli:ui slidernx g @spartan-ng/cli:ui sliderUsage
import { HlmSliderImports } from '@spartan-ng/helm/slider';<hlm-slider />Examples
Range
Use an array with two values for a range slider.
import { Component, signal } from '@angular/core';
import { HlmSliderImports } from '@spartan-ng/helm/slider';
@Component({
selector: 'spartan-slider-range',
imports: [HlmSliderImports],
styles: `
:host {
display: block;
width: 60%;
}
`,
template: `
<hlm-slider [(value)]="value" />
`,
})
export class SliderRange {
public readonly value = signal([25, 50]);
}Multiple Thumbs
Use an array with multiple values for multiple thumbs.
import { Component, signal } from '@angular/core';
import { HlmSliderImports } from '@spartan-ng/helm/slider';
@Component({
selector: 'spartan-slider-multiple-thumbs',
imports: [HlmSliderImports],
styles: `
:host {
display: block;
width: 60%;
}
`,
template: `
<hlm-slider [(value)]="value" />
`,
})
export class SliderMultipleThumbs {
public readonly value = signal([10, 20, 70]);
}Vertical
Use orientation="vertical" for a vertical slider.
import { Component, signal } from '@angular/core';
import { HlmSliderImports } from '@spartan-ng/helm/slider';
@Component({
selector: 'spartan-slider-vertical',
imports: [HlmSliderImports],
styles: `
:host {
display: flex;
gap: 1.5rem;
}
`,
template: `
<hlm-slider [(value)]="value" orientation="vertical" />
<hlm-slider [(value)]="value2" orientation="vertical" />
`,
})
export class SliderVertical {
public readonly value = signal([50]);
public readonly value2 = signal([25]);
}Disabled
Use the disabled input to disable the slider.
import { Component, signal } from '@angular/core';
import { HlmSliderImports } from '@spartan-ng/helm/slider';
@Component({
selector: 'spartan-slider-disabled',
imports: [HlmSliderImports],
styles: `
:host {
display: block;
width: 60%;
}
`,
template: `
<hlm-slider [(value)]="value" [disabled]="true" />
`,
})
export class SliderDisabled {
public readonly value = signal([50]);
}Ticks
import { Component, signal } from '@angular/core';
import { HlmSliderImports } from '@spartan-ng/helm/slider';
@Component({
selector: 'spartan-slider-ticks',
imports: [HlmSliderImports],
styles: `
:host {
display: block;
width: 60%;
}
`,
template: `
<hlm-slider [(value)]="value" [showTicks]="true" />
`,
})
export class SliderTicks {
public readonly value = signal([50]);
}Ticks with label
import { Component, signal } from '@angular/core';
import { HlmLabel } from '@spartan-ng/helm/label';
import { HlmSliderImports } from '@spartan-ng/helm/slider';
@Component({
selector: 'spartan-slider-ticks-with-label',
imports: [HlmSliderImports, HlmLabel],
styles: `
:host {
display: block;
width: 60%;
}
`,
template: `
<div class="flex flex-col gap-2">
<label hlmLabel for="volume">Volume</label>
<hlm-slider id="volume" [(value)]="value" [showTicks]="true" />
</div>
`,
})
export class SliderTicksWithLabel {
public readonly value = signal([50]);
}Prevent thumb overlap
Use minStepsBetweenThumbs to avoid thumbs with equal values.
import { Component, signal } from '@angular/core';
import { HlmSliderImports } from '@spartan-ng/helm/slider';
@Component({
selector: 'spartan-slider-prevent-thumb-overlap',
imports: [HlmSliderImports],
styles: `
:host {
display: block;
width: 60%;
}
`,
template: `
<hlm-slider [(value)]="value" [step]="10" [minStepsBetweenThumbs]="1" />
`,
})
export class SliderPreventThumbOverlap {
public readonly value = signal([20, 50]);
}Draggable Range
Use draggableRange to enable moving all thumbs together when dragging by the selected range.
import { Component, signal } from '@angular/core';
import { HlmSliderImports } from '@spartan-ng/helm/slider';
@Component({
selector: 'spartan-slider-draggable-range',
imports: [HlmSliderImports],
styles: `
:host {
display: block;
width: 60%;
}
`,
template: `
<hlm-slider [(value)]="value" [draggableRange]="true" />
`,
})
export class SliderDraggableRange {
public readonly value = signal([25, 50]);
}Draggable Range Only
Use draggableRangeOnly in pair with draggableRange to allow only dragging the range.
import { Component, signal } from '@angular/core';
import { HlmSliderImports } from '@spartan-ng/helm/slider';
@Component({
selector: 'spartan-slider-draggable-range-only',
imports: [HlmSliderImports],
styles: `
:host {
display: block;
width: 60%;
}
`,
template: `
<hlm-slider [(value)]="value" [draggableRange]="true" [draggableRangeOnly]="true" />
`,
})
export class SliderDraggableRangeOnly {
public readonly value = signal([25, 50]);
}Form
import { Component, signal } from '@angular/core';
import { form, FormField, FormRoot, required } from '@angular/forms/signals';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmFieldImports } from '@spartan-ng/helm/field';
import { HlmSliderImports } from '@spartan-ng/helm/slider';
@Component({
selector: 'spartan-slider-form',
imports: [HlmSliderImports, FormRoot, FormField, HlmButtonImports, HlmFieldImports],
host: { class: 'w-full max-w-xs' },
template: `
<form [formRoot]="form">
<hlm-field-group>
<hlm-field>
<label hlmFieldLabel for="volume">Volume</label>
<hlm-slider id="volume" [formField]="form.volume" />
<p hlmFieldDescription>Set your speaker volume.</p>
</hlm-field>
<hlm-field orientation="horizontal">
<button hlmBtn type="submit">Submit</button>
</hlm-field>
</hlm-field-group>
</form>
`,
})
export class SliderForm {
protected readonly _model = signal<{ volume: number[] }>({ volume: [25] });
public readonly form = form(
this._model,
(schemaPath) => {
required(schemaPath.volume, { message: 'Volume is required' });
},
{
submission: {
action: async () => {
const model = this._model();
console.log(model);
},
},
},
);
}RTL
To enable RTL support in spartan-ng, see the RTL configuration guide.
import { Directionality } from '@angular/cdk/bidi';
import { Component, computed, effect, inject, signal, untracked } from '@angular/core';
import { TranslateService, Translations } from '@spartan-ng/app/app/shared/translate.service';
import { HlmLabel } from '@spartan-ng/helm/label';
import { HlmSliderImports } from '@spartan-ng/helm/slider';
@Component({
selector: 'spartan-slider-rtl-preview',
imports: [HlmLabel, HlmSliderImports],
providers: [Directionality],
host: {
class: 'grid w-full max-w-sm gap-3',
'[dir]': '_dir()',
},
template: `
<label hlmLabel>{{ _t()['volume'] }}</label>
<hlm-slider [(value)]="_value" />
`,
})
export class SliderRtlPreview {
private readonly _directionality = inject(Directionality);
private readonly _language = inject(TranslateService).language;
protected readonly _value = signal([60]);
private readonly _translations: Translations = {
en: { dir: 'ltr', values: { volume: 'Volume' } },
ar: { dir: 'rtl', values: { volume: 'مستوى الصوت' } },
he: { dir: 'rtl', values: { volume: 'עוצמת קול' } },
};
private readonly _translation = computed(() => this._translations[this._language()]);
protected readonly _t = computed(() => this._translation().values);
protected readonly _dir = computed(() => this._translation().dir);
constructor() {
effect(() => {
const dir = this._dir();
untracked(() => this._directionality.valueSignal.set(dir));
});
}
}Brain API
BrnSliderRange
Selector: [brnSliderRange]
ExportAs: brnSliderRange
BrnSliderThumb
Selector: [brnSliderThumb]
ExportAs: brnSliderThumb
BrnSliderTick
Selector: [brnSliderTick]
ExportAs: brnSliderTick
BrnSliderTrack
Selector: [brnSliderTrack]
ExportAs: brnSliderTrack
BrnSlider
Selector: [brnSlider]
ExportAs: brnSlider
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | `brn-slider-${++nextId}` | Unique identifier for the slider element. Auto-generated if not provided. |
| aria-label | string | null | null | Accessibility label for the slider. Forwarded to all thumbs. |
| aria-labelledby | string | null | null | ID of the element that labels this slider for accessibility. Forwarded to all thumbs. |
| value | number[] | [] | The current slider value(s). For single-thumb sliders, this contains one value. For range sliders, values are kept sorted in ascending order. |
| min | number | 0 | Minimum allowed slider value. |
| max | number | 100 | Maximum allowed slider value. |
| step | number | 1 | Step increment used when changing values. |
| minStepsBetweenThumbs | number | 0 | Minimum number of steps required between thumbs in a range slider. |
| maxStepsBetweenThumbs | number | Number.POSITIVE_INFINITY | Maximum number of steps allowed between thumbs in a range slider. |
| preventStepOverThumb | boolean | false | Whether a thumb is prevented from being dragged past its neighbouring thumbs in a range slider. |
| disabled | boolean | false | Whether the slider is disabled. |
| inverted | boolean | false | Whether the slider direction is inverted. |
| orientation | 'horizontal' | 'vertical' | 'horizontal' | Slider orientation. |
| showTicks | boolean | false | Whether tick marks should be displayed. |
| maxTicks | number | 25 | Maximum number of ticks to render. Excess ticks are evenly distributed. |
| tickLabelInterval | number | 2 | Interval at which tick labels are shown. A value of `2` shows a label every second tick. |
| formatTick | (tick: number) => string | (tick) => tick.toString() | Defines how the tick should be displayed in the UI. |
| draggableRange | boolean | false | Whether dragging the selected range should move all thumbs together. |
| draggableRangeOnly | boolean | false | Whether only dragging the range should work (overrides normal track clicks). |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| valueChange | number[] | - | Emits when the value changes. |
Helm API
HlmSlider
Selector: hlm-slider, brn-slider [hlm]
ExportAs: hlmSlider
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | `brn-slider-${++nextId}` | Unique identifier for the slider element. Auto-generated if not provided. |
| value | number[] | [] | The current slider value(s). For single-thumb sliders, this contains one value. For range sliders, values are kept sorted in ascending order. |
| disabled | boolean | false | Whether the slider is disabled. |
| min | number | 0 | Minimum allowed slider value. |
| max | number | 100 | Maximum allowed slider value. |
| step | number | 1 | Step increment used when changing values. |
| minStepsBetweenThumbs | number | 0 | Minimum number of steps required between thumbs in a range slider. |
| maxStepsBetweenThumbs | number | Number.POSITIVE_INFINITY | Maximum number of steps allowed between thumbs in a range slider. |
| preventStepOverThumb | boolean | false | Whether a thumb is prevented from being dragged past its neighbouring thumbs in a range slider. |
| inverted | boolean | false | Whether the slider direction is inverted. |
| orientation | 'horizontal' | 'vertical' | 'horizontal' | Slider orientation. |
| showTicks | boolean | false | Whether tick marks should be displayed. |
| maxTicks | number | 25 | Maximum number of ticks to render. Excess ticks are evenly distributed. |
| tickLabelInterval | number | 2 | Interval at which tick labels are shown. A value of `2` shows a label every second tick. |
| formatTick | (tick: number) => string | (tick) => tick.toString() | Defines how the tick should be displayed in the UI. |
| draggableRange | boolean | false | Whether dragging the selected range should move all thumbs together. |
| draggableRangeOnly | boolean | false | Whether only dragging the range should work (overrides normal track clicks). |
| aria-label | string | null | null | Accessibility label for the slider. Forwarded to all thumbs. |
| aria-labelledby | string | null | null | ID of the element that labels this slider for accessibility. Forwarded to all thumbs. |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| valueChange | number[] | - | Emits when the value changes. |
On This Page