Slider

lightning:slider

An input range slider for specifying a value between two specified numbers. This component requires API version 41.0 and later.

For Aura components only. For LWC development, use lightning-slider.

For Use In

Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline

A lightning:slider component is a horizontal or vertical slider for specifying a value between two specified numbers. For example, this slider can be used to capture user input about order quantity or when you want to use an input field of type="range". To orient the slider vertically, set type="vertical". Older browsers that don’t support the slider fall back and treat it as type="text".

This component implements styling from slider in the Lightning Design System.

Here’s an example of a slider with a step increment of 10.

1<aura:component>
2  <aura:attribute name="myval" default="10" type="Integer" />
3  <lightning:slider
4    step="10"
5    value="{!v.myval}"
6    onchange="{! c.handleChange }"
7  />
8</aura:component>

The client-side controller displays the updated value on the slider.

1({
2  handleChange: function (cmp, event) {
3    alert(cmp.get("v.value"));
4  },
5});

Input Validation 

Client-side input validation is available for this component. Note that a disabled slider is always valid. To programmatically display error messages on invalid fields, use the reportValidity() method. For custom validity error messages, display the message using setCustomValidity() and reportValidity(). For more information, see the lightning:input documentation.

Usage Considerations 

Use the onchange event handler to detect changes to the slider value instead of the onblur handler. Browsers such as Safari don’t give focus to the slider so the blur event doesn’t fire.

By default, the min and max values are 0 and 100, but you can specify your own values. If you specify your own step increment value, you can drag the slider based on the step increment only. If you set the value lower than the min value, then the value is set to the min value. Similarly, setting the value higher than the max value results in the value being set to the max value.

For precise numerical values, we recommend using the lightning:input component of type="number" instead.

Attributes 

NameDescriptionTypeDefaultRequired
bodyThe body of the component. In markup, this is everything in the body of the tag.Aura.Component[]
classA CSS class for the outer element, in addition to the component's base classes.String
disabledThe disabled value of the input range. This value default to false.Booleanfalse
labelThe text label for the input range. Provide your own label to describe the slider. Otherwise, no label is displayed.String
maxThe max value of the input range. This value defaults to 100.Integer100
messageWhenBadInputError message to be displayed when a bad input is detected.String
messageWhenPatternMismatchError message to be displayed when a pattern mismatch is detected.String
messageWhenRangeOverflowError message to be displayed when a range overflow is detected.String
messageWhenRangeUnderflowError message to be displayed when a range underflow is detected.String
messageWhenStepMismatchError message to be displayed when a step mismatch is detected.String
messageWhenTooLongError message to be displayed when the value is too long.String
messageWhenTypeMismatchError message to be displayed when a type mismatch is detected.String
messageWhenValueMissingError message to be displayed when the value is missing.String
minThe min value of the input range. This value defaults to 0.Integer0
onblurThe action triggered when the slider releases focus.Aura.Action
onchangeThe action triggered when the slider value changes. You must pass any newly selected value back to the slider component to bind the new value to the slider.String
onfocusThe action triggered when the slider receives focus.Aura.Action
sizeThe size value of the input range. This value default to empty, which is the base. Supports x-small, small, medium, and large.String
stepThe step increment value of the input range. Example steps include 0.1, 1, or 10. This value defaults to 1.String1
titleDisplays tooltip text when the mouse moves over the element.String
typeThe type of the input range position. This value defaults to horizontal.Stringhorizontal
valueThe numerical value of the input range. This value defaults to 0.Integer0
variantThe variant changes the appearance of the slider. Accepted variants include standard and label-hidden. This value defaults to standard.Stringstandard

Methods 

NameDescriptionArgument NameArgument TypeArgument Description
blurRemoves keyboard focus on the slider.
checkValidityReturns the valid property value (Boolean) on the ValidityState object to indicate whether the slider value has any validity errors.
focusSets focus on the slider.
reportValidityDisplay error messages if the slider value is invalid.
setCustomValiditySets a custom error message to be displayed when the slider value is submitted.messageStringThe string that describes the error. If message is an empty string, the error message is reset.
showHelpMessageIfInvalidDisplays error messages on the slider. The slider value is invalid if it fails at least one constraint validation and returns false when checkValidity() is called.