Slider API
Import
Section titled “Import”import { UNSTABLE_Slider as Slider } from '@cimpress-ui/react';Controlled/uncontrolled usage
Section titled “Controlled/uncontrolled usage”This component can be used in a controlled or uncontrolled way.
In the controlled way, this component doesn’t maintain its own internal state, and its value is provided by the parent component. Use the controlled way when you need to be able to change the state of this component in other parts of your application.
In the uncontrolled way, this component maintains its own internal state, and can optionally notify the parent component when its internal state changes. Use the uncontrolled way when you don’t need to change the state of this component in other parts of your application.
import { UNSTABLE_Slider as Slider, Stack } from '@cimpress-ui/react';import { useState } from 'react';
export default function Example() { const [value, setValue] = useState([30, 70]);
return ( <Stack gap={16}> <Slider label="Price range (controlled)" value={value} onChange={setValue} minValue={0} maxValue={200} /> <Slider label="Price range (uncontrolled)" defaultValue={[30, 70]} minValue={0} maxValue={200} /> </Stack> );}Accessibility notes
Section titled “Accessibility notes”Slider follows the ARIA slider pattern. See the linked page for a list of available keyboard interactions.
Slider requires a textual label to remain accessible to assistive technologies. See our accessibility guide for more details.
API reference
Section titled “API reference”Slider
Section titled “Slider”Allows users to select one or more values within a range.
- Ref<HTMLDivElement>
-
The
reftype for this component.
UNSTABLE_SliderProps<T extends number | number[] = number>
- string
description
Section titled “ description ” -
A description for the field. Provides a hint such as specific requirements for what to choose.
- T
value
Section titled “ value ” -
The current value (controlled).
- T
defaultValue
Section titled “ defaultValue ” -
The default value (uncontrolled).
- (value: T) => void
onChange
Section titled “ onChange ” -
Handler that is called when the value changes.
- (value: T) => void
onChangeEnd
Section titled “ onChangeEnd ” -
Handler that is called when the slider stops moving.
- string
-
The
<form>element to associate the input with. The value of this attribute must be the id of a<form>in the same document. See MDN. - T extends number[] ? string[] : string
-
The name of the input element, used when submitting an HTML form. See MDN.
- boolean
withInput
Section titled “ withInput ” -
Show input fields for slider values.
- boolean
showLabels
Section titled “ showLabels ” -
Show static labels for minimum and maximum values.
- string
-
The element's unique identifier. See MDN.
- boolean
data-cim-style-root
Section titled “ data-cim-style-root ” -
Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- string
UNSAFE_className
Section titled “ UNSAFE_className ” -
Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- CSSProperties
UNSAFE_style
Section titled “ UNSAFE_style ” -
Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
- string
label
Section titled “ label ” -
The content to display as the label.
- string
aria-label
Section titled “ aria-label ” -
Defines a string value that labels the current element.
- string
aria-labelledby
Section titled “ aria-labelledby ” -
Identifies the element (or elements) that labels the current element.
- string
aria-describedby
Section titled “ aria-describedby ” -
Identifies the element (or elements) that describes the object.
- string
aria-details
Section titled “ aria-details ” -
Identifies the element (or elements) that provide a detailed, extended description for the object.
- boolean
isDisabled
Section titled “ isDisabled ” -
Whether the whole Slider is disabled.
- number
minValue
Section titled “ minValue ” - Defaults to 0 .
The slider's minimum value.
- number
maxValue
Section titled “ maxValue ” - Defaults to 100 .
The slider's maximum value.
- number
- Defaults to 1 .
The slider's step value.
StyleProps
- Responsive<Spacing | "auto">
margin
Section titled “ margin ” -
The amount of margin applied to all edges of this component.
- Responsive<Spacing | "auto">
marginX
Section titled “ marginX ” -
The amount of margin applied to the left and right edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginY
Section titled “ marginY ” -
The amount of margin applied to the top and bottom edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginTop
Section titled “ marginTop ” -
The amount of margin applied to the top edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginRight
Section titled “ marginRight ” -
The amount of margin applied to the right edge of this component. Takes priority over
marginXandmargin. - Responsive<Spacing | "auto">
marginBottom
Section titled “ marginBottom ” -
The amount of margin applied to the bottom edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginLeft
Section titled “ marginLeft ” -
The amount of margin applied to the left edge of this component. Takes priority over
marginXandmargin.