Skip to content

feat: add direction to Slider for tracks that don't follow the locale - #10537

Open
dylanpulver wants to merge 2 commits into
adobe:mainfrom
dylanpulver:feat/slider-fixed-direction
Open

dylanpulver wants to merge 2 commits into
adobe:mainfrom
dylanpulver:feat/slider-fixed-direction

Conversation

@dylanpulver

@dylanpulver dylanpulver commented Aug 30, 2026

Copy link
Copy Markdown

Closes #10112

direction?: 'ltr' | 'rtl' as you suggested. A boolean could only pin to the UI's opposite, so it can't express an RTL track in an LTR UI — the manga case.

Omitted, behaviour is exactly as before. Set, the hooks resolve state.direction ?? localeDirection and SliderFill anchors physically; vertical is unaffected.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices
  • I understand every change in this PR and can explain why it's there.
  • If AI-assisted, I followed our AI contribution guidance and pointed my assistant at CLAUDE.md.

📝 Test Instructions:

Storybook: Slider Pinned Direction.

26 tests, each proven live by a mutant; the boolean-shaped fill mutant fails exactly the direction="rtl" one. Upstream's 49 slider tests, unchanged, give identical results. yarn jest slider Slider 233/233; yarn lint clean.

🧢 Your Project:

Personal open-source contribution.

@yihuiliao

Copy link
Copy Markdown
Member

Thanks for the PR! You'll need to sign the CLA and then close/re-open the PR to trigger a re-run

@snowystinger

Copy link
Copy Markdown
Member

Thanks for the PR. I had a chat with Adobe's i18n and linguistics, the direction of the slider isn't restricted to only being LTR in an RTL UI. There are cases where it will need to be RTL in an LTR ui.

If it represents reading or navigation order, the content's reading direction may determine it.
Therefore, a Japanese manga should typically start from the right, even within an LTR UI.

Instead of a boolean, I'm leaning more towards something like direction?: 'ltr' | 'rtl'

dylanpulver and others added 2 commits September 8, 2026 02:36
A horizontal slider mirrors with the UI locale, which is right when the track
represents reading order. It is wrong when the direction comes from the content
instead: a media playback bar stays left to right in an RTL UI, and a track over
right-to-left content such as a manga page stays right to left in an LTR UI.

`direction?: 'ltr' | 'rtl'` pins the track. Omitted, the slider mirrors the
locale exactly as before.

Direction is read in four places and they mirror by two mechanisms. `useSlider`
(track click, track drag) and `useSliderThumb` (arrow keys, drag, thumb `left`)
invert in JS and now resolve `state.direction ?? localeDirection`, so both pinned
directions fall out of the existing `direction === 'rtl'` checks. `SliderFill`
mirrors in CSS via `insetInlineStart`, which resolves against the document and is
therefore the wrong edge for a pinned track; it now anchors physically, `left`
for a pinned ltr track and `right` for a pinned rtl one, and keeps
`insetInlineStart` untouched when nothing is pinned. Vertical is unaffected.

The prop lives on `SliderState` rather than being threaded through both hooks,
following `orientation`, which means S2 picks it up through `SliderBaseProps`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011M5uTyCU4WcNTsPvGrErDo
pointerDown installs mouseup/touchend/pointerup listeners on window. The two
stacked-thumb tests never released the pointer, so on React 16 and 17 the
listeners outlived the unmounted component and fired during a later test.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011M5uTyCU4WcNTsPvGrErDo
@dylanpulver
dylanpulver force-pushed the feat/slider-fixed-direction branch from 3db72f5 to c856427 Compare September 8, 2026 00:36
@dylanpulver dylanpulver changed the title feat: add hasFixedDirection to Slider for non-mirrored media controls feat: add direction to Slider for tracks that don't follow the locale Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support passing in direction to useSlider for media controls

3 participants