Slider
This component allows users to make selection from a range of values
Basic Usage
import { Slider } from '@krakentech/coral';
<Slider />Properties
value
const [sliderValue, setSliderValue] = useState(10);
<Slider value={sliderValue} />
<Button
color="secondary"
size="small"
onClick={() => setSliderValue(40)}
>
Change slider value
</Button>defaultValue
<Slider defaultValue={50} />disabled
<Slider disabled />error / errorMessage
<Slider error errorMessage="Please select a value" />isAnimated
<Slider isAnimated={false} />label
<Slider label="Select a value" />min / max
<Slider min={1} max={1000} />optional
Note: You must pass a
labeland haveshowLabelsset to true to see the optional indicator
<Slider label="Select a value" optional />showLabels
<Slider label="Select a value" showLabels={false} />step
<Slider step={10} />valueLabelDisplay
<Slider valueLabelDisplay="on" />valueLabelFormat
<Slider
min={0}
max={100}
valueLabelFormat={(value) => `${value}%`}
valueLabelDisplay="on"
/>Event Handling
<Slider onChange={(sliderValue) => {}} onBlur={() => {}} />Full API
| Name | Type | Default |
|---|---|---|
ariaLabel | stringThe aria-label of the slider thumb. | Slider control |
value | number
| |
defaultValue | numberThe default value to be selected when the component is first rendered. | |
disabled | booleanIf | false |
error | booleanIf | |
errorMessage | stringIf set, the | |
getAriaValueText | (value: number) => stringAccepts a function which returns a string value that provides a user-friendly name for the current value of the slider. This is important for screen reader users. | |
isAnimated | booleanIf | true |
label | stringThe accessible label for the slider. | |
max | numberThe maximum allowed value of the slider. This should not be equal to min. | 100 |
min | numberThe minimum allowed value of the slider. This should not be equal to max. | 0 |
name | stringName attribute of the hidden | |
onBlur | FocusEventHandler<HTMLDivElement>Callback fired when the slider loses user focus. | |
onChange | SliderChangeHandlerCallback fired each time the user changes the slider value.
| |
optional | booleanAdd an optional flag to the label for this field (controlled by https://coral-oe.vercel.app/?path=/docs/guides-configuration—docs#overrides-optional-indicator optionalIndicator). This should be set to true if you have set this field to be optional in your validation schema. | false |
showLabels | booleanDisplay the field label, including the currently-selected value. | true |
step | numberThe granularity with which the slider can step through values. (A “discrete” slider.) The min prop serves as the origin for the valid values. We recommend (max - min) to be evenly divisible by the step. | 1 |
valueLabelDisplay | SliderValueLabelDisplayControls when the value label is displayed:
| auto |
valueLabelFormat | (value: number) => stringA function that formats the value label. This is useful for displaying currency, percentages, etc. |
Design
Good to know
Choose a slider if you want to make a selection from a range of values, the perk of a slider is the change in value is reflected immediately to the user.
Component breakdown
- Button slider: Soho Lights
- Button label: Dusty Sky
- Button label: Heading 6
- Slider: Ink