Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core): RTL Phase 4 — SideNav collapse, TreeList, Slider directional behavior (#4520)

nynexman4464c3f233ffc8e1
diff --git a/.changeset/rtl-phase4-behavioral.md b/.changeset/rtl-phase4-behavioral.md
new file mode 100644
index 0000000000..84e740f014
--- /dev/null
+++ b/.changeset/rtl-phase4-behavioral.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] RTL Phase 4 (behavioral): mirror directional behavior that logical-CSS and icon name-swaps alone couldn't fix. SideNavCollapseButton and TreeListItem now compose `rtlStyles.mirror` on the icon wrapper outside the state rotation, so the chevrons point toward the correct edge in every collapsed/expanded × LTR/RTL combination. TreeList connector/guide lines position via logical `inset-inline-start`/`inset-inline-end` so they mirror to the inline-start (right) edge under RTL alongside the chevron and row indent. Slider positions its thumb, fill, and marks via logical `inset-inline-start` and flips the physical centering transform under RTL, and its pointer/click math measures the value fraction from the inline-start (right) edge under RTL — so a click at 25% of the track maps to 75 instead of 25.
+@nynexman4464
diff --git a/packages/core/src/SideNav/SideNavCollapseButton.tsx b/packages/core/src/SideNav/SideNavCollapseButton.tsx
index db24b61c3c..5a6660a1d8 100644
--- a/packages/core/src/SideNav/SideNavCollapseButton.tsx
+++ b/packages/core/src/SideNav/SideNavCollapseButton.tsx
@@ -23,7 +23,7 @@ import {durationVars, easeVars} from '../theme/tokens.stylex';
import {getIcon} from '../Icon/globalIconRegistry';
import {Button} from '../Button';
import type {BaseProps} from '../BaseProps';
-import {composeEventHandlers} from '../utils';
+import {composeEventHandlers, rtlStyles} from '../utils';
import {
useSideNavCollapse,
type SideNavCollapseState,
@@ -131,12 +131,14 @@ export function SideNavCollapseButton({
onClick={composeEventHandlers(onClickProp, toggle)}
icon={
children ?? (
- <span
- {...stylex.props(
- styles.chevron,
- isCollapsed && styles.chevronCollapsed,
- )}>
- {getIcon('chevronLeft')}
+ <span {...stylex.props(rtlStyles.mirror)}>
+ <span
+ {...stylex.props(
+ styles.chevron,
+ isCollapsed && styles.chevronCollapsed,
+ )}>
+ {getIcon('chevronLeft')}
+ </span>
</span>
)
}
diff --git a/packages/core/src/Slider/Slider.test.tsx b/packages/core/src/Slider/Slider.test.tsx
index 4532adfedb..b54991ed6a 100644
--- a/packages/core/src/Slider/Slider.test.tsx
+++ b/packages/core/src/Slider/Slider.test.tsx
@@ -89,7 +89,9 @@ describe('Slider', () => {
render(<Slider label="Volume" value={value} min={0} max={100} />);
const slider = screen.getByRole('slider');
expect(slider).toHaveAttribute('aria-valuenow', String(expectedValue));
- expect(slider).toHaveStyle({left: expectedPosition});
+ // Thumb positions via the logical `inset-inline-start` so it mirrors
+ // under RTL (see RTL Phase 4). In LTR this resolves to the left edge.
+ expect(slider).toHaveStyle({insetInlineStart: expectedPosition});
},
);
@@ -507,6 +509,89 @@ describe('Slider', () => {
expect(document.activeElement).toBe(slider);
});
+ // --- RTL pointer value mapping (RTL Phase 4) ---
+ // Contract: the inline-start edge (value = min) is the RIGHT edge under RTL,
+ // so the same physical click maps to the mirrored value relative to LTR.
+ // `valueDisplay="none"` keeps the thumb a direct child of the track element
+ // (no Tooltip wrapper) so the mocked rect lands on trackRef.
+
+ it('maps a track click to the LTR value in the default direction', () => {
+ const handleChange = vi.fn();
+ render(
+ <Slider
+ label="Volume"
+ value={0}
+ min={0}
+ max={100}
+ valueDisplay="none"
+ onChange={handleChange}
+ />,
+ );
+ const track = screen.getByRole('slider').parentElement!;
+ track.getBoundingClientRect = () =>
+ ({
+ left: 0,
+ top: 0,
+ right: 200,
+ bottom: 20,
+ width: 200,
+ height: 20,
+ x: 0,
+ y: 0,
+ toJSON: () => {},
+ });
+
+ // Click at 25% of the track from the left (x=50 of 200) → value 25 in LTR.
+ fireEvent.pointerDown(track, {clientX: 50, clientY: 10, pointerId: 1});
+ expect(handleChange).toHaveBeenLastCalledWith(25);
+ });
+
+ it('mirrors a track click to the RTL value when the track is rtl', () => {
+ const handleChange = vi.fn();
+ render(
+ <Slider
+ label="Volume"
+ value={0}
+ min={0}
+ max={100}
+ valueDisplay="none"
+ onChange={handleChange}
+ />,
+ );
+ const track = screen.getByRole('slider').parentElement!;
+ track.getBoundingClientRect = () =>
+ ({
+ left: 0,
+ top: 0,
+ right: 200,
+ bottom: 20,
+ width: 200,
+ height: 20,
+ x: 0,
+ y: 0,
+ toJSON: () => {},
+ });
+
+ // Force the track's computed direction to rtl (isRtlElement reads this).
+ const realGetComputedStyle = window.getComputedStyle;
+ const gcsSpy = vi
+ .spyOn(window, 'getComputedStyle')
+ .mockImplementation((el: Element, pseudo?: string | null) => {
+ if (el === track) {
+ return {direction: 'rtl'} as CSSStyleDeclaration;
+ }
+ return realGetComputedStyle(el, pseudo ?? undefined);
+ });
+
+ // Same physical click at 25% from the left (x=50). Under RTL the inline
+ // start is the right edge, so fraction = (right - x)/width = 150/200 = 0.75
+ // → value 75 (the mirror of the LTR value 25).
+ fireEvent.pointerDown(track, {clientX: 50, clientY: 10, pointerId: 1});
+ expect(handleChange).toHaveBeenLastCalledWith(75);
+
+ gcsSpy.mockRestore();
+ });
+
// --- Mark label click snapping ---
it('clicking a mark label snaps to that mark value, not pointer position', () => {
diff --git a/packages/core/src/Slider/Slider.tsx b/packages/core/src/Slider/Slider.tsx
index 6245268939..2051c27153 100644
--- a/packages/core/src/Slider/Slider.tsx
+++ b/packages/core/src/Slider/Slider.tsx
@@ -41,6 +41,7 @@ import {useTooltip} from '../Tooltip';
import {VisuallyHidden} from '../VisuallyHidden';
import type {InputStatus} from '../Field/types';
import {mergeProps, mergeRefs} from '../utils';
+import {isRtlElement} from '../hooks/isRtlElement';
import type {BaseProps} from '../BaseProps';
import type {SizeValue} from '../utils/types';
import {themeProps} from '../utils/themeProps';
@@ -192,8 +193,8 @@ const styles = stylex.create({
borderRadius: radiusVars['--radius-full'],
},
trackHorizontal: {
- left: 0,
- right: 0,
+ insetInlineStart: 0,
+ insetInlineEnd: 0,
height: TRACK_SIZE,
top: '50%',
transform: 'translateY(-50%)',
@@ -202,7 +203,7 @@ const styles = stylex.create({
top: 0,
bottom: 0,
width: TRACK_SIZE,
- left: '50%',
+ insetInlineStart: '50%',
transform: 'translateX(-50%)',
},
filledTrack: {
@@ -217,7 +218,7 @@ const styles = stylex.create({
},
filledTrackVertical: {
width: TRACK_SIZE,
- left: '50%',
+ insetInlineStart: '50%',
transform: 'translateX(-50%)',
},
thumb: {
@@ -239,9 +240,17 @@ const styles = stylex.create({
},
thumbHorizontal: {
top: '50%',
+ // The thumb is positioned via logical `insetInlineStart`, which resolves
+ // from the right edge under RTL. The centering translate is a physical
+ // (screen-space) transform, so it must flip its X direction under RTL to
+ // keep the thumb centered on the value point.
+ transform: {
+ default: 'translate(-50%, -50%)',
+ ':is([dir="rtl"] *)': 'translate(50%, -50%)',
+ },
},
thumbVertical: {
- left: '50%',
+ insetInlineStart: '50%',
transform: 'translate(-50%, 50%)',
},
thumbHover: {
@@ -277,14 +286,14 @@ const styles = stylex.create({
position: 'absolute',
},
marksContainerHorizontal: {
- left: 0,
- right: 0,
+ insetInlineStart: 0,
+ insetInlineEnd: 0,
top: '50%',
},
marksContainerVertical: {
top: 0,
bottom: 0,
- left: '50%',
+ insetInlineStart: '50%',
},
mark: {
position: 'absolute',
@@ -294,7 +303,10 @@ const styles = stylex.create({
markHorizontal: {
width: 2,
height: 8,
- transform: 'translate(-50%, -50%)',
+ transform: {
+ default: 'translate(-50%, -50%)',
+ ':is([dir="rtl"] *)': 'translate(50%, -50%)',
+ },
},
markVertical: {
height: 2,
@@ -309,12 +321,15 @@ const styles = stylex.create({
whiteSpace: 'nowrap',
},
markLabelHorizontal: {
- transform: 'translateX(-50%)',
+ transform: {
+ default: 'translateX(-50%)',
+ ':is([dir="rtl"] *)': 'translateX(50%)',
+ },
top: THUMB_SIZE / 2 + 4,
},
markLabelVertical: {
transform: 'translateY(50%)',
- left: THUMB_SIZE / 2 + 4,
+ insetInlineStart: THUMB_SIZE / 2 + 4,
},
});
@@ -460,7 +475,12 @@ export function Slider({ref, ...props}: SliderProps) {
let percent: number;
if (isHorizontal) {
- percent = (clientX - rect.left) / rect.width;
+ // In RTL the inline-start (value = min) is the right edge, so measure
+ // the pointer fraction from the right instead of the left. Detected
+ // from the track's computed direction (lazy, only on pointer move).
+ percent = isRtlElement(track)
+ ? (rect.right - clientX) / rect.width
+ : (clientX - rect.left) / rect.width;
} else {
// Vertical: bottom = min, top = max
percent = 1 - (clientY - rect.top) / rect.height;
@@ -693,7 +713,7 @@ export function Slider({ref, ...props}: SliderProps) {
const percent = getPercent(val, min, max);
const positionStyle = isHorizontal
- ? {left: `${percent}%`}
+ ? {insetInlineStart: `${percent}%`}
: {bottom: `${percent}%`, left: '50%'};
// In range mode each thumb keeps a short individual name that composes
@@ -784,13 +804,13 @@ export function Slider({ref, ...props}: SliderProps) {
const p0 = getPercent(v0, min, max);
const p1 = getPercent(v1, min, max);
if (isHorizontal) {
- return {left: `${p0}%`, width: `${p1 - p0}%`};
+ return {insetInlineStart: `${p0}%`, width: `${p1 - p0}%`};
}
return {bottom: `${p0}%`, height: `${p1 - p0}%`};
}
const p = getPercent(values[0], min, max);
if (isHorizontal) {
- return {left: '0%', width: `${p}%`};
+ return {insetInlineStart: '0%', width: `${p}%`};
}
return {bottom: '0%', height: `${p}%`};
})();
@@ -915,7 +935,7 @@ export function Slider({ref, ...props}: SliderProps) {
{marks.map(mark => {
const percent = getPercent(mark.value, min, max);
const markPos = isHorizontal
- ? {left: `${percent}%`}
+ ? {insetInlineStart: `${percent}%`}
: {bottom: `${percent}%`};
return (
<div key={mark.value}>
diff --git a/packages/core/src/TreeList/TreeListBranches.tsx b/packages/core/src/TreeList/TreeListBranches.tsx
index 67640c6f7c..12eb8fdb4c 100644
--- a/packages/core/src/TreeList/TreeListBranches.tsx
+++ b/packages/core/src/TreeList/TreeListBranches.tsx
@@ -37,10 +37,10 @@ const styles = stylex.create({
},
verticalLine: {
borderRadius: 1,
- left: 0,
+ insetInlineStart: 0,
margin: 'auto',
position: 'absolute',
- right: 0,
+ insetInlineEnd: 0,
width: LINE_WIDTH,
backgroundColor: colorVars['--color-border-emphasized'],
},
@@ -92,7 +92,7 @@ export function TreeListBranches({
key={level}
{...mergeProps(stylex.props(styles.container), {
style: {
- left: branchOffset,
+ insetInlineStart: branchOffset,
},
})}>
<div
@@ -109,7 +109,7 @@ export function TreeListBranches({
<div
{...mergeProps(stylex.props(styles.container), {
style: {
- left: `calc(${BRANCH_MARGIN} + ${nestedLevel - 1} * ${LEVEL_INDENT})`,
+ insetInlineStart: `calc(${BRANCH_MARGIN} + ${nestedLevel - 1} * ${LEVEL_INDENT})`,
},
})}>
<div
diff --git a/packages/core/src/TreeList/TreeListItem.tsx b/packages/core/src/TreeList/TreeListItem.tsx
index 1140779cf4..c22273dabc 100644
--- a/packages/core/src/TreeList/TreeListItem.tsx
+++ b/packages/core/src/TreeList/TreeListItem.tsx
@@ -25,7 +25,7 @@ import {
typeScaleVars,
} from '../theme/tokens.stylex';
import {getIcon} from '../Icon/globalIconRegistry';
-import {mergeProps} from '../utils';
+import {mergeProps, rtlStyles} from '../utils';
import {useLinkComponent} from '../Link/useLinkComponent';
import {TreeListBranches} from './TreeListBranches';
import type {TreeListDensity, TreeListVariant} from './TreeListTypes';
@@ -386,12 +386,14 @@ export function TreeListItem({
);
const chevronIcon = (
- <span
- {...stylex.props(
- styles.chevronSvg,
- isExpanded ? styles.chevronExpanded : styles.chevronCollapsed,
- )}>
- {getIcon('chevronRight')}
+ <span {...stylex.props(rtlStyles.mirror)}>
+ <span
+ {...stylex.props(
+ styles.chevronSvg,
+ isExpanded ? styles.chevronExpanded : styles.chevronCollapsed,
+ )}>
+ {getIcon('chevronRight')}
+ </span>
</span>
);