Sliderv0.4.2Documentation Under Review
An interactive slider component for selecting values within a range, featuring single value selection, range selection, and optional segment markers.
Overview
The Slider component provides an intuitive way for users to select numeric values within a defined range. Built on Radix UI primitives, it supports single value selection, range selection with dual thumbs, and visual segment markers for precise value indication.
Installation
npm install @pmi/catalyst-sliderUsage
Basic Single Value Slider
Range Slider
Select a range of values using two thumbs.
Slider with Segments
Display visual markers at each step position.
Range Slider with Segments
Combine range selection with segment markers.
Disabled State
Custom Styling
Customize the slider appearance with Tailwind CSS classes.
Real-World Product Examples
API Reference
SliderRoot
The root container that manages slider state and behavior.
Prop
Type
SliderTrack
The track element that contains the slider range.
Prop
Type
SliderRange
The filled portion of the track representing the selected range.
Prop
Type
SliderThumb
The draggable handle for selecting values. Use multiple thumbs for range selection.
Prop
Type
SliderSegment
Visual markers displayed at step positions along the track.
Prop
Type
Accessibility
Keyboard Navigation
- Arrow Left/Down: Decrease value by one step
- Arrow Right/Up: Increase value by one step
- Home: Jump to minimum value
- End: Jump to maximum value
- Page Down: Decrease value by larger increment
- Page Up: Increase value by larger increment
ARIA Attributes
role="slider": Applied to thumb elementsaria-label: Required for each thumb to identify purposearia-valuemin: Minimum valuearia-valuemax: Maximum valuearia-valuenow: Current valuearia-disabled: Indicates disabled state
Best Practices
- Always provide aria-label: Each thumb needs a descriptive label
- Use appropriate step sizes: Ensure values are meaningful for your use case
- Consider range constraints: Use
minStepsBetweenThumbsfor range sliders - Provide visual feedback: Show current value(s) near the slider
- Test keyboard navigation: Verify all keyboard interactions work correctly
Design Guidelines
When to Use
- Adjusting numeric values within a defined range
- Volume, brightness, or other continuous controls
- Filtering data by numeric ranges
- Setting price ranges or time periods
- Configuring threshold values
When Not to Use
- Selecting from discrete options (use RadioGroup or Select)
- Binary choices (use Switch or Checkbox)
- Precise numeric input required (use TextField)
- Many small increments (consider TextField with validation)
Understanding Segment Positioning
When using segments with sliders, a MutationObserver is employed to fix positioning issues caused by Radix UI's internal calculations. The observer removes calc() offsets that can misalign segments with their intended step positions.
How it works:
- Segments are positioned at calculated percentages along the track
- The observer watches for style changes on thumb parent elements
- When a
calc()expression is detected, it's simplified to the base percentage - This ensures segments align perfectly with step positions
This is necessary because Radix UI applies transforms to center thumbs at their values, which can conflict with segment positioning.
Custom Styling Patterns
The custom styling example demonstrates using nested selectors to style Radix UI primitives that don't expose direct class props:
// Target slider thumbs through role selector
'[&_[role=slider]]:bg-pmi-aqua-500';
// Style on hover
'[&_[role=slider]:hover]:bg-pmi-aqua-700';
// Focus-visible state
'[&_[role=slider]:focus-visible]:bg-pmi-aqua-500';This pattern allows consistent theming across all slider components while maintaining the primitive structure.