Skip to content

[Toolkit][Shadcn] Add slider recipe#3481

Open
Amoifr wants to merge 5 commits intosymfony:3.xfrom
Amoifr:feat/toolkit-shadcn-slider
Open

[Toolkit][Shadcn] Add slider recipe#3481
Amoifr wants to merge 5 commits intosymfony:3.xfrom
Amoifr:feat/toolkit-shadcn-slider

Conversation

@Amoifr
Copy link
Copy Markdown
Contributor

@Amoifr Amoifr commented Apr 18, 2026

Q A
Bug fix? no
New feature? yes
Deprecations? no
Documentation? no
Issues Part of #3233
License MIT

Adds the slider recipe to the Shadcn kit.

Part of the split of #3466 into one PR per component, tracking #3233.

Snapshots will be regenerated after rework.

@Amoifr
Copy link
Copy Markdown
Contributor Author

Amoifr commented Apr 19, 2026

Main example

Capture.video.du.2026-04-19.11-46-16.mp4

@Amoifr
Copy link
Copy Markdown
Contributor Author

Amoifr commented Apr 19, 2026

Range example

Capture.video.du.2026-04-19.12-00-30.mp4

@Amoifr
Copy link
Copy Markdown
Contributor Author

Amoifr commented Apr 19, 2026

Multiple Thumbs example

Capture.video.du.2026-04-19.12-01-22.mp4

@Amoifr
Copy link
Copy Markdown
Contributor Author

Amoifr commented Apr 19, 2026

Vertical example

Capture.video.du.2026-04-19.12-02-13.mp4

@Amoifr
Copy link
Copy Markdown
Contributor Author

Amoifr commented Apr 19, 2026

Disabled example

Capture.video.du.2026-04-19.12-03-46.mp4

@Amoifr
Copy link
Copy Markdown
Contributor Author

Amoifr commented Apr 19, 2026

Controlled example

Capture.video.du.2026-04-19.12-08-45.mp4

@Amoifr
Copy link
Copy Markdown
Contributor Author

Amoifr commented Apr 19, 2026

RTL example

Capture.video.du.2026-04-19.12-30-50.mp4

@Amoifr Amoifr force-pushed the feat/toolkit-shadcn-slider branch from d1af4c1 to ac78111 Compare April 19, 2026 10:32
@Amoifr Amoifr marked this pull request as ready for review April 19, 2026 10:33
@Amoifr Amoifr requested a review from Kocal as a code owner April 19, 2026 10:33
@carsonbot carsonbot added Feature New Feature Toolkit Status: Needs Review Needs to be reviewed labels Apr 19, 2026
import { Controller } from '@hotwired/stimulus';

export default class extends Controller {
static targets = ['track', 'range', 'thumb', 'input'];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we find another naming for thumb, they call this thumbs in shadcns doc but not in their code, maybe we can call it handle like popular UI kits ( Radix, chakra ui ... )
Wdyt ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for raising this! I went back and forth on the naming and landed on thumb to stay aligned with shadcn upstream, which uses SliderPrimitive.Thumb and data-slot="slider-thumb". The ARIA pattern itself puts role="slider" on that element, so "thumb" is also the accessible name it inherits in assistive tech docs. Since this kit mirrors shadcn's vocabulary, I'd rather keep thumb here to avoid a one-recipe divergence. If the broader kit leans towards Radix/Chakra-style handle in the future, happy to revisit it kit-wide in one pass. WDYT? 🙏

_isDisabled() {
return this.element.getAttribute('aria-disabled') === 'true' || this.element.matches('[data-disabled]');
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should clear the event listeners in the disconnect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks! Fixed in e1fc1e1 — using a single AbortController for the static thumb/track listeners, plus a second one scoped to the drag that's also aborted in disconnect(). Bonus: the inline arrow functions are now safely removable, and interrupting a drag mid-Turbo-nav no longer leaks window listeners.

"$schema": "../../../schema-kit-recipe-v1.json",
"type": "component",
"name": "Slider",
"description": "An input that allows the user to select a value from a given range.",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An input where the user selects a value from within a given range.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much nicer wording, adopted in e1fc1e1. Thanks!

@zairigimad
Copy link
Copy Markdown
Contributor

From the videos, it looks great. I left some minor comments

@Amoifr Amoifr force-pushed the feat/toolkit-shadcn-slider branch from 8c6ba39 to e55ce0e Compare April 27, 2026 12:54
Add a per-thumb `aria-label` so screen readers can distinguish thumbs in
range/multi-thumb sliders. Falls back to "Slider" (single) or
"Slider thumb X of Y" (multiple); customizable via the new `labels` prop
(comma-separated string or array).
@Amoifr
Copy link
Copy Markdown
Contributor Author

Amoifr commented Apr 30, 2026

While reviewing #3483 (input-otp), @Kocal pointed out a missing per-input `aria-label`, and the same gap was hiding here on the slider thumbs: each `` had `aria-valuenow` but no label, which makes range/multi-thumb sliders confusing for screen-reader users (you hear "slider 25 / slider 50" with no way to know which is min and which is max).

Just pushed a tiny a11y patch to fix that:

  • Each thumb now gets a default `aria-label` — `Slider` for a single thumb, `Slider thumb X of Y` for multi-thumb.
  • New optional `labels` prop (comma-separated string or array) lets you provide friendlier labels:
    ```twig
    <twig:Slider value="25,50" labels="Min,Max" />
    <twig:Slider value="20,50,80" labels="Low,Medium,High" />
    ```
  • Range / Multiple examples updated, snapshots regenerated.

Force-pushed on top of the existing branch. Happy to adjust the wording or the prop name if you'd prefer something else! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New Feature Status: Needs Review Needs to be reviewed Toolkit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants