-
Notifications
You must be signed in to change notification settings - Fork 21
Labels
π¦ componentsRelated to the @swisspost/design-system-components packageRelated to the @swisspost/design-system-components package
Milestone
Description
π Description
Select numeric values by dragging one or more thumbs along a track.
βΏ Accessibility
- Usable with mouse, keyboard, or touch.
- The slider has
role="slider"and the following ARIA attributes:aria-valuenow,aria-valuemin,aria-valuemax. - The slider must have a label, either hidden via
aria-labelor visible viaaria-labelledby. - If the numbers represent meaningful values (e.g., days of the week), use
aria-valuetextto expose the current value in a human-understandable way (e.g.,"Monday"). - If the slider has multiple thumbs, the role and ARIA attributes are set on each thumb instead of the slider element itself.
βοΈ Requirements
- The slider is composed of a fixed track and one or more sliding thumbs.
- The track is horizontal by default but can be configured as vertical using the
verticalproperty. - A
rangeproperty adds a second thumb to allow selection of a numeric range. - Two thumbs cannot cross each other.
- The minimum value of the track defaults to
0but can be configured with aminproperty. - The maximum value of the track defaults to
100but can be configured with amaxproperty. - The step size defaults to
1but can be configured with astepproperty. - The step is based on
minif specified, otherwise onvalue, or0if neither is provided (e.g., withmin="3"andstep="2", thumbs snap to 3, 5, 7, 9, β¦). min,max, andstepmust be numbers.minmust be lower thanmax.stepmust be lower thanmax - min.- The
valueproperty represents the position of the thumb(s):- If
rangeis false β a single number. - If
rangeis true β a tuple[number, number].
- If
- Default placement of thumbs:
- Single thumb β centered between
minandmax(rounded). - Range β placed at one-third and two-thirds of the track.
- Single thumb β centered between
- Thumbs always snap to the closest step.
- Example: if
step="3", a value of 1 snaps to 0, a value of 2 snaps to 3.
- Example: if
- Thumbs never move past the
minormax. - Values can optionally be formatted.
- Values are always shown in ascending order.
- Ticks can be added via a slotted
<datalist>with<option>elements. - If the options have labels, they are shown alongside the ticks.
- Ticks and labels are always displayed above the track (or to the left for vertical sliders) so they remain visible when using touch. (It is recommended to implement this layout using CSS grid to ensure consistent alignment between the track, ticks, and labels.)
- The slider emits:
- an
inputevent whenever a thumb moves (multiple emissions while sliding). - a
changeevent whenever a thumb position is committed (emitted once when the user releases the thumb).
- an
π§ͺ Testing
Single, range, and vertical slider scenarios.
- Correct snapping to steps with different min/max/step configurations.
- Default thumb placement logic.
- Value formatting behavior.
- Ticks and labels rendering correctly via
<datalist>. - Event emissions (
inputvschange). - Preventing thumbs from crossing or exceeding min/max.
- Accessibility: ARIA attributes, keyboard navigation, screen reader value announcements.
- Responsiveness on touch devices and across browsers.
π» Proposed implementation
// default slider min is 0, max is 100, step is 1 and value is 50
<post-slider />
// range slider min is 0, max is 100, step is 1 and value is [33, 67]
<post-slider range="true" />
// slider with ticks
<post-slider>
<datalist id="values">
<option value="0"></option>
<option value="25"></option>
<option value="50"></option>
<option value="75"></option>
<option value="100"></option>
</datalist>
</post-slider>
// slider with ticks
<post-slider max="6" value="1" >
<datalist>
<option value="0" label="Sunday"></option>
<option value="1" label="Monday"></option>
<option value="2" label="Tuesday"></option>
<option value="3" label="Wednesday"></option>
<option value="4" label="Thursday"></option>
<option value="5" label="Friday"></option>
<option value="6" label="Saturday"></option>
</datalist>
</post-slider>π References
- https://www.w3.org/WAI/ARIA/apg/patterns/slider/
- https://www.w3.org/WAI/ARIA/apg/patterns/slider-multithumb/
- https://ant.design/components/slider
- https://mui.com/material-ui/react-slider
- https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/range
π Tasks
- Implement component functionality
- Create developer-only documentation in Storybook
- Add functional tests
- Add React integration tests
- Add Angular integration tests
Metadata
Metadata
Assignees
Labels
π¦ componentsRelated to the @swisspost/design-system-components packageRelated to the @swisspost/design-system-components package
Type
Projects
Status
π§ In Review