Examples
Types
SliderOnChangeEvent
The slider's onChange
prop accepts an event
parameter of the following types:
React.MouseEvent
React.KeyboardEvent
React.FormEvent<HTMLInputElement>
React.TouchEvent
React.FocusEvent<HTMLInputElement>
The SliderOnChangeEvent
type is a union of the above event types, and can be imported and used in your code like in the following code snippet:
import { Slider, SliderOnChangeEvent } from '@patternfly/react-core';
<Slider onChange={(event: SliderOnChangeEvent) => {}} />
Props
Slider
Name | Type | Default | Description |
---|---|---|---|
areCustomStepsContinuous | boolean | false | Flag indicating if the slider is discrete for custom steps. This will cause the slider to snap to the closest value. |
aria-describedby | string | One or more id's to use for the slider thumb's accessible description. | |
aria-labelledby | string | One or more id's to use for the slider thumb's accessible label. | |
className | string | Additional classes added to the slider. | |
customSteps | SliderStepObject[] | Array of custom slider step objects (value and label of each step) for the slider. | |
endActions | React.ReactNode | Actions placed at the end of the slider. | |
hasTooltipOverThumb | boolean | false | |
inputAriaLabel | string | 'Slider value input' | Accessible label for the input field. |
inputLabel | string | number | Text label that is place after the input field. | |
inputPosition | 'aboveThumb' | 'right' | 'end' | 'end' | Position of the input. Note "right" is deprecated. Use "end" instead |
inputValue | number | 0 | Value displayed in the input field. |
isDisabled | boolean | false | Adds disabled styling, and disables the slider and the input component if present. |
isInputVisible | boolean | false | Flag to show value input field. |
Deprecated: leftActions | React.ReactNode | Use startActions instead. Actions placed at the start of the slider. | |
max | number | 100 | The maximum permitted value. |
min | number | 0 | The minimum permitted value. |
onChange | ( event: SliderOnChangeEvent, value: number, inputValue?: number, setLocalInputValue?: React.Dispatch<React.SetStateAction<number>> ) => void | Value change callback. This is called when the slider value changes. | |
Deprecated: rightActions | React.ReactNode | Use endActions instead. Actions placed to the right of the slider. | |
showBoundaries | boolean | true | Flag to indicate if boundaries should be shown for slider that does not have custom steps. |
showTicks | boolean | false | Flag to indicate if ticks should be shown for slider that does not have custom steps. |
startActions | React.ReactNode | Actions placed at the start of the slider. | |
step | number | 1 | The step interval. |
thumbAriaLabel | string | 'Value' | |
value | number | 0 | Current value of the slider. |
SliderStepObject
Name | Type | Default | Description |
---|---|---|---|
labelrequired | string | The display label for the step value. This is also used for the aria-valuetext attribute. | |
valuerequired | number | Value of the step. This value is a percentage of the slider where the tick is drawn. | |
isLabelHidden | boolean | Flag to hide the label. |
CSS variables
Expand or collapse column | Selector | Variable | Value | |
---|---|---|---|---|
.pf-v5-c-slider | --pf-v5-c-slider--value | 0 | ||
.pf-v5-c-slider | --pf-v5-c-slider__step--Left | 0 | ||
.pf-v5-c-slider | --pf-v5-c-slider__rail--PaddingTop | 1rem | ||
--pf-v5-c-slider__rail--PaddingTop --pf-v5-global--spacer--md $pf-v5-global--spacer--md pf-size-prem(16px) 1rem | ||||
.pf-v5-c-slider | --pf-v5-c-slider__rail--PaddingBottom | 1rem | ||
--pf-v5-c-slider__rail--PaddingBottom --pf-v5-global--spacer--md $pf-v5-global--spacer--md pf-size-prem(16px) 1rem | ||||
.pf-v5-c-slider | --pf-v5-c-slider__rail-track--Height | 0.25rem | ||
.pf-v5-c-slider | --pf-v5-c-slider__rail-track--before--base--BackgroundColor | #d2d2d2 | ||
--pf-v5-c-slider__rail-track--before--base--BackgroundColor --pf-v5-global--BorderColor--100 $pf-v5-global--BorderColor--100 $pf-v5-color-black-300 #d2d2d2 | ||||
.pf-v5-c-slider | --pf-v5-c-slider__rail-track--before--fill--BackgroundColor | #2b9af3 | ||
--pf-v5-c-slider__rail-track--before--fill--BackgroundColor --pf-v5-global--active-color--300 $pf-v5-global--active-color--300 $pf-v5-color-blue-300 #2b9af3 | ||||
.pf-v5-c-slider | --pf-v5-c-slider__rail-track--before--BorderRadius | 30em | ||
--pf-v5-c-slider__rail-track--before--BorderRadius --pf-v5-global--BorderRadius--lg $pf-v5-global--BorderRadius--lg 30em | ||||
.pf-v5-c-slider | --pf-v5-c-slider__rail-track--before--fill--BackgroundColor--gradient-stop | 0 | ||
--pf-v5-c-slider__rail-track--before--fill--BackgroundColor--gradient-stop --pf-v5-c-slider--value 0 | ||||
.pf-v5-c-slider | --pf-v5-c-slider__rail-track--before--fill--direction | right | ||
.pf-v5-c-slider | --pf-v5-c-slider__steps--FontSize | 0.875rem | ||
--pf-v5-c-slider__steps--FontSize --pf-v5-global--FontSize--sm $pf-v5-global--FontSize--sm pf-font-prem(14px) 0.875rem | ||||
.pf-v5-c-slider | --pf-v5-c-slider__steps--Height | 0.875rem | ||
--pf-v5-c-slider__steps--Height --pf-v5-c-slider__steps--FontSize --pf-v5-global--FontSize--sm $pf-v5-global--FontSize--sm pf-font-prem(14px) 0.875rem | ||||
.pf-v5-c-slider | --pf-v5-c-slider__step-tick--Top | 1rem | ||
--pf-v5-c-slider__step-tick--Top --pf-v5-global--spacer--md $pf-v5-global--spacer--md pf-size-prem(16px) 1rem | ||||
.pf-v5-c-slider | --pf-v5-c-slider__step-tick--Width | 0.25rem | ||
.pf-v5-c-slider | --pf-v5-c-slider__step-tick--Height | 0.25rem | ||
.pf-v5-c-slider | --pf-v5-c-slider__step-tick--BackgroundColor | #8a8d90 | ||
--pf-v5-c-slider__step-tick--BackgroundColor --pf-v5-global--BorderColor--200 $pf-v5-global--BorderColor--200 $pf-v5-color-black-500 #8a8d90 | ||||
.pf-v5-c-slider | --pf-v5-c-slider__step-tick--TranslateX | -50% | ||
.pf-v5-c-slider | --pf-v5-c-slider__step-tick--BorderRadius | 30em | ||
--pf-v5-c-slider__step-tick--BorderRadius --pf-v5-global--BorderRadius--lg $pf-v5-global--BorderRadius--lg 30em | ||||
.pf-v5-c-slider | --pf-v5-c-slider__step--m-active__slider-tick--BackgroundColor | #06c | ||
--pf-v5-c-slider__step--m-active__slider-tick--BackgroundColor --pf-v5-global--primary-color--100 $pf-v5-global--primary-color--100 $pf-v5-color-blue-400 #06c | ||||
.pf-v5-c-slider | --pf-v5-c-slider__step--first-child__step-tick--TranslateX | 0 | ||
.pf-v5-c-slider | --pf-v5-c-slider__step--last-child__step-tick--TranslateX | -100% | ||
.pf-v5-c-slider | --pf-v5-c-slider__step-label--TranslateX | -50% | ||
.pf-v5-c-slider | --pf-v5-c-slider__step-label--Top | calc(2rem + 0.25rem) | ||
--pf-v5-c-slider__step-label--Top calc(--pf-v5-global--spacer--xl + --pf-v5-c-slider__rail-track--Height) calc($pf-v5-global--spacer--xl + 0.25rem) calc(pf-size-prem(32px) + 0.25rem) calc(2rem + 0.25rem) | ||||
.pf-v5-c-slider | --pf-v5-c-slider__step--first-child__step-label--TranslateX | 0 | ||
.pf-v5-c-slider | --pf-v5-c-slider__step--last-child__step-label--TranslateX | -100% | ||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--Top | calc(0.25rem / 2 + 1rem) | ||
--pf-v5-c-slider__thumb--Top calc(--pf-v5-c-slider__rail-track--Height / 2 + --pf-v5-global--spacer--md) calc(0.25rem / 2 + $pf-v5-global--spacer--md) calc(0.25rem / 2 + pf-size-prem(16px)) calc(0.25rem / 2 + 1rem) | ||||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--Width | 1rem | ||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--Height | 1rem | ||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--Left | 0 | ||
--pf-v5-c-slider__thumb--Left --pf-v5-c-slider--value 0 | ||||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--BackgroundColor | #06c | ||
--pf-v5-c-slider__thumb--BackgroundColor --pf-v5-global--primary-color--100 $pf-v5-global--primary-color--100 $pf-v5-color-blue-400 #06c | ||||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--TranslateX | -50% | ||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--TranslateY | -50% | ||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--BorderRadius | 30em | ||
--pf-v5-c-slider__thumb--BorderRadius --pf-v5-global--BorderRadius--lg $pf-v5-global--BorderRadius--lg 30em | ||||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--BoxShadow--base | 0 0 0 2px #fff,
0 0 0 3px #06c | ||
--pf-v5-c-slider__thumb--BoxShadow--base 0 0 0 2px --pf-v5-global--BackgroundColor--100,
0 0 0 3px --pf-v5-global--primary-color--100 0 0 0 2px $pf-v5-global--BackgroundColor--100,
0 0 0 3px $pf-v5-global--primary-color--100 0 0 0 2px $pf-v5-color-white,
0 0 0 3px $pf-v5-color-blue-400 0 0 0 2px #fff,
0 0 0 3px #06c | ||||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--hover--BoxShadow | 0 0 0 2px #fff,
0 0 0 3px #06c | ||
--pf-v5-c-slider__thumb--hover--BoxShadow --pf-v5-c-slider__thumb--BoxShadow--base 0 0 0 2px --pf-v5-global--BackgroundColor--100,
0 0 0 3px --pf-v5-global--primary-color--100 0 0 0 2px $pf-v5-global--BackgroundColor--100,
0 0 0 3px $pf-v5-global--primary-color--100 0 0 0 2px $pf-v5-color-white,
0 0 0 3px $pf-v5-color-blue-400 0 0 0 2px #fff,
0 0 0 3px #06c | ||||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--focus--BoxShadow | 0 0 0 2px #fff,
0 0 0 3px #06c | ||
--pf-v5-c-slider__thumb--focus--BoxShadow --pf-v5-c-slider__thumb--BoxShadow--base 0 0 0 2px --pf-v5-global--BackgroundColor--100,
0 0 0 3px --pf-v5-global--primary-color--100 0 0 0 2px $pf-v5-global--BackgroundColor--100,
0 0 0 3px $pf-v5-global--primary-color--100 0 0 0 2px $pf-v5-color-white,
0 0 0 3px $pf-v5-color-blue-400 0 0 0 2px #fff,
0 0 0 3px #06c | ||||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--active--BoxShadow | 0 0 0 2px #fff,
0 0 0 3px #06c,
0 0 2px 5px #bee1f4 | ||
--pf-v5-c-slider__thumb--active--BoxShadow --pf-v5-c-slider__thumb--BoxShadow--base,
0 0 2px 5px --pf-v5-global--active-color--200 0 0 0 2px --pf-v5-global--BackgroundColor--100,
0 0 0 3px --pf-v5-global--primary-color--100,
0 0 2px 5px $pf-v5-global--active-color--200 0 0 0 2px $pf-v5-global--BackgroundColor--100,
0 0 0 3px $pf-v5-global--primary-color--100,
0 0 2px 5px $pf-v5-global--active-color--200 0 0 0 2px $pf-v5-color-white,
0 0 0 3px $pf-v5-color-blue-400,
0 0 2px 5px $pf-v5-color-blue-100 0 0 0 2px #fff,
0 0 0 3px #06c,
0 0 2px 5px #bee1f4 | ||||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--before--Width | 44px | ||
--pf-v5-c-slider__thumb--before--Width --pf-v5-global--target-size--MinWidth $pf-v5-global--target-size--MinWidth 44px | ||||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--before--Height | 44px | ||
--pf-v5-c-slider__thumb--before--Height --pf-v5-global--target-size--MinHeight $pf-v5-global--target-size--MinHeight 44px | ||||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--before--BorderRadius | 30em | ||
--pf-v5-c-slider__thumb--before--BorderRadius --pf-v5-global--BorderRadius--lg $pf-v5-global--BorderRadius--lg 30em | ||||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--before--TranslateX | -50% | ||
.pf-v5-c-slider | --pf-v5-c-slider__thumb--before--TranslateY | -50% | ||
.pf-v5-c-slider | --pf-v5-c-slider__value--MarginLeft | 1rem | ||
--pf-v5-c-slider__value--MarginLeft --pf-v5-global--spacer--md $pf-v5-global--spacer--md pf-size-prem(16px) 1rem | ||||
.pf-v5-c-slider | --pf-v5-c-slider__value--c-form-control--width-base | 3.5ch | ||
.pf-v5-c-slider | --pf-v5-c-slider__value--c-form-control--width-chars | 3 | ||
.pf-v5-c-slider | --pf-v5-c-slider__value--c-form-control--Width | calc(3.5ch + (3 * 1ch)) | ||
--pf-v5-c-slider__value--c-form-control--Width calc(--pf-v5-c-slider__value--c-form-control--width-base + (--pf-v5-c-slider__value--c-form-control--width-chars * 1ch)) calc(3.5ch + (3 * 1ch)) | ||||
.pf-v5-c-slider | --pf-v5-c-slider__value--m-floating--TranslateX | -50% | ||
.pf-v5-c-slider | --pf-v5-c-slider__value--m-floating--TranslateY | -100% | ||
.pf-v5-c-slider | --pf-v5-c-slider__value--m-floating--Left | 0 | ||
--pf-v5-c-slider__value--m-floating--Left --pf-v5-c-slider--value 0 | ||||
.pf-v5-c-slider | --pf-v5-c-slider__value--m-floating--ZIndex | 200 | ||
--pf-v5-c-slider__value--m-floating--ZIndex --pf-v5-global--ZIndex--sm $pf-v5-global--ZIndex--sm 200 | ||||
.pf-v5-c-slider | --pf-v5-c-slider__actions--MarginRight | 0.5rem | ||
--pf-v5-c-slider__actions--MarginRight --pf-v5-global--spacer--sm $pf-v5-global--spacer--sm pf-size-prem(8px) 0.5rem | ||||
.pf-v5-c-slider | --pf-v5-c-slider__main--actions--MarginLeft | 0.5rem | ||
--pf-v5-c-slider__main--actions--MarginLeft --pf-v5-global--spacer--sm $pf-v5-global--spacer--sm pf-size-prem(8px) 0.5rem | ||||
.pf-v5-c-slider | --pf-v5-c-slider--m-disabled__rail-track--before--fill--BackgroundColor | #8a8d90 | ||
--pf-v5-c-slider--m-disabled__rail-track--before--fill--BackgroundColor --pf-v5-global--palette--black-500 $pf-v5-color-black-500 #8a8d90 | ||||
.pf-v5-c-slider | --pf-v5-c-slider--m-disabled__step--m-active__slider-tick--BackgroundColor | #4f5255 | ||
--pf-v5-c-slider--m-disabled__step--m-active__slider-tick--BackgroundColor --pf-v5-global--palette--black-700 $pf-v5-color-black-700 #4f5255 | ||||
.pf-v5-c-slider | --pf-v5-c-slider--m-disabled__thumb--BackgroundColor | #4f5255 | ||
--pf-v5-c-slider--m-disabled__thumb--BackgroundColor --pf-v5-global--palette--black-700 $pf-v5-color-black-700 #4f5255 | ||||
:where(.pf-v5-m-dir-rtl, [dir=rtl]) .pf-v5-c-slider | --pf-v5-c-slider__rail-track--before--fill--direction | left | ||
.pf-v5-c-slider.pf-m-disabled | --pf-v5-c-slider__rail-track--before--fill--BackgroundColor | #8a8d90 | ||
--pf-v5-c-slider__rail-track--before--fill--BackgroundColor --pf-v5-c-slider--m-disabled__rail-track--before--fill--BackgroundColor --pf-v5-global--palette--black-500 $pf-v5-color-black-500 #8a8d90 | ||||
.pf-v5-c-slider.pf-m-disabled | --pf-v5-c-slider__step--m-active__slider-tick--BackgroundColor | #4f5255 | ||
--pf-v5-c-slider__step--m-active__slider-tick--BackgroundColor --pf-v5-c-slider--m-disabled__step--m-active__slider-tick--BackgroundColor --pf-v5-global--palette--black-700 $pf-v5-color-black-700 #4f5255 | ||||
.pf-v5-c-slider.pf-m-disabled | --pf-v5-c-slider__thumb--BackgroundColor | #4f5255 | ||
--pf-v5-c-slider__thumb--BackgroundColor --pf-v5-c-slider--m-disabled__thumb--BackgroundColor --pf-v5-global--palette--black-700 $pf-v5-color-black-700 #4f5255 | ||||
.pf-v5-c-slider.pf-m-disabled .pf-v5-c-slider__thumb | --pf-v5-c-slider__thumb--BoxShadow | none | ||
.pf-v5-c-slider__step.pf-m-active | --pf-v5-c-slider__step-tick--BackgroundColor | #06c | ||
--pf-v5-c-slider__step-tick--BackgroundColor --pf-v5-c-slider__step--m-active__slider-tick--BackgroundColor --pf-v5-global--primary-color--100 $pf-v5-global--primary-color--100 $pf-v5-color-blue-400 #06c | ||||
.pf-v5-c-slider__step:first-child | --pf-v5-c-slider__step-tick--TranslateX | 0 | ||
--pf-v5-c-slider__step-tick--TranslateX --pf-v5-c-slider__step--first-child__step-tick--TranslateX 0 | ||||
.pf-v5-c-slider__step:first-child | --pf-v5-c-slider__step-label--TranslateX | 0 | ||
--pf-v5-c-slider__step-label--TranslateX --pf-v5-c-slider__step--first-child__step-label--TranslateX 0 | ||||
.pf-v5-c-slider__step:last-child | --pf-v5-c-slider__step-tick--TranslateX | -100% | ||
--pf-v5-c-slider__step-tick--TranslateX --pf-v5-c-slider__step--last-child__step-tick--TranslateX -100% | ||||
.pf-v5-c-slider__step:last-child | --pf-v5-c-slider__step-label--TranslateX | -100% | ||
--pf-v5-c-slider__step-label--TranslateX --pf-v5-c-slider__step--last-child__step-label--TranslateX -100% | ||||
.pf-v5-c-slider__thumb:hover | --pf-v5-c-slider__thumb--BoxShadow | 0 0 0 2px #fff,
0 0 0 3px #06c | ||
--pf-v5-c-slider__thumb--BoxShadow --pf-v5-c-slider__thumb--hover--BoxShadow --pf-v5-c-slider__thumb--BoxShadow--base 0 0 0 2px --pf-v5-global--BackgroundColor--100,
0 0 0 3px --pf-v5-global--primary-color--100 0 0 0 2px $pf-v5-global--BackgroundColor--100,
0 0 0 3px $pf-v5-global--primary-color--100 0 0 0 2px $pf-v5-color-white,
0 0 0 3px $pf-v5-color-blue-400 0 0 0 2px #fff,
0 0 0 3px #06c | ||||
.pf-v5-c-slider__thumb:focus | --pf-v5-c-slider__thumb--BoxShadow | 0 0 0 2px #fff,
0 0 0 3px #06c | ||
--pf-v5-c-slider__thumb--BoxShadow --pf-v5-c-slider__thumb--focus--BoxShadow --pf-v5-c-slider__thumb--BoxShadow--base 0 0 0 2px --pf-v5-global--BackgroundColor--100,
0 0 0 3px --pf-v5-global--primary-color--100 0 0 0 2px $pf-v5-global--BackgroundColor--100,
0 0 0 3px $pf-v5-global--primary-color--100 0 0 0 2px $pf-v5-color-white,
0 0 0 3px $pf-v5-color-blue-400 0 0 0 2px #fff,
0 0 0 3px #06c | ||||
.pf-v5-c-slider__thumb:active | --pf-v5-c-slider__thumb--BoxShadow | 0 0 0 2px #fff,
0 0 0 3px #06c,
0 0 2px 5px #bee1f4 | ||
--pf-v5-c-slider__thumb--BoxShadow --pf-v5-c-slider__thumb--active--BoxShadow --pf-v5-c-slider__thumb--BoxShadow--base,
0 0 2px 5px --pf-v5-global--active-color--200 0 0 0 2px --pf-v5-global--BackgroundColor--100,
0 0 0 3px --pf-v5-global--primary-color--100,
0 0 2px 5px $pf-v5-global--active-color--200 0 0 0 2px $pf-v5-global--BackgroundColor--100,
0 0 0 3px $pf-v5-global--primary-color--100,
0 0 2px 5px $pf-v5-global--active-color--200 0 0 0 2px $pf-v5-color-white,
0 0 0 3px $pf-v5-color-blue-400,
0 0 2px 5px $pf-v5-color-blue-100 0 0 0 2px #fff,
0 0 0 3px #06c,
0 0 2px 5px #bee1f4 | ||||
.pf-v5-c-slider__value.pf-m-floating | --pf-v5-c-slider__value--MarginLeft | 0 | ||
.pf-v5-c-slider__main ~ .pf-v5-c-slider__actions | --pf-v5-c-slider__actions--MarginRight | 0 |
View source on GitHub