Skip to main content

Slider

Use cases:

  • Interact with data visualization
  • Input for numeric values
  • Dynamic filters
  • Have a visually labelled scale for the user to choose a value from

Example

Low Mid High

Declaration

<rapid-slider>
<rapid-slider-label position="0"> Low </rapid-slider-label>
<rapid-slider-label position="50"> Mid </rapid-slider-label>
<rapid-slider-label position="100"> High </rapid-slider-label>
</rapid-slider>

Usage

@customElement({
name: 'my-element',
template: html`
<div>
<label>Simple slider</label>
<rapid-slider @change="${(x, ctx) => x.handleSliderChanged(ctx.event)}" value="${sync((x) => x.sliderValue, 'number')}"></rapid-slider>
</div>
<div>
<label>Slider with labels and step value of 1</label>
<rapid-slider
value="${sync((x) => x.sliderValue, 'number')}"
@change="${(x, ctx) => x.handleLabelSliderChanged(ctx.event)}"
min="0"
max="100"
step="1"
value="50"
>
<rapid-slider-label position="0"> Low </rapid-slider-label>
<rapid-slider-label position="50"> Mid </rapid-slider-label>
<rapid-slider-label position="100"> High </rapid-slider-label>
</rapid-slider>
</div>
`,
})
export class MyElement extends GenesisElement {
@observable sliderValue: number;
handleSliderChanged(event: Event): void {
console.log((event.target as HTMLInputElement).value);
}

handleLabelSliderChanged(e: Event): void {
// both sync values and event values will be the same
console.log(this.sliderValue)
console.log((event.target as HTMLInputElement).value);
}
}

Use of the <rapid-slider-label> is optional.

API

Property and attribute binding examples for Genesis Component syntax.

Attributes

NameTypeDescriptionExample
readonlybooleanThe slider is for display only, and cannot be changed by the user.
<rapid-slider readonly>
disabledbooleanSimilar to readonly, but component is also greyed out.
<rapid-slider disabled>
formstringAssociates this component to a form. Form id needs to be passed. If no Id informed, then it will be associated with the ancestor form.
<rapid-slider form="myForm">
maxnumberDefines maximum number of the slider.
<rapid-slider max=50>
minnumberDefines minimum number of the slider.
<rapid-slider min=10>
stepnumberDefines the value of each step of the slider.
<rapid-slider step=5>
valuenumberDefines a value for the component when it is created. If omitted the default is halfway between the min and max values.
<rapid-slider value=20>
orientationstringDefines the orientation: vertical or horizontal.
<rapid-slider orientation="horizontal">

Properties

This component doesn't have any properties which are not also controlled via attributes.

Slots

SlotUse
checked-indicatorThe checked indicator.
trackThe track of the slider.
track-startThe track-start visual indicator.
thumbThe slider thumb.

Parts

PartDescription
controlThe element representing the visual radio control.
labelThe label.
positioning-regionThe region used to position the elements of the slider.
trackThe region containing the track elements.
track-startThe element wrapping the track start slot.
thumb-containerThe thumb container element which is programmatically positioned.
thumbThe thumb element.

Events fired

EventTypeUseExample
changeeventEmits a custom change event when the checked state changes. Access the value on the event via .target.value.
<rapid-slider @change="${(x) => x.myChangeHandler(event)}">

Events listened to

This component doesn't listen to any events.

Further details

This component is an implementation of an HTML range slider element.