Skip to content

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

TypeScript

fix(core): RTL Phase 4c — ProgressBar, Switch, Layer directional behavior (#4562)

nynexman446485f502225f31
diff --git a/.changeset/rtl-phase4c-behavioral.md b/.changeset/rtl-phase4c-behavioral.md
new file mode 100644
index 0000000000..17ca1e656f
--- /dev/null
+++ b/.changeset/rtl-phase4c-behavioral.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] RTL Phase 4c — make three animated/interactive behaviors direction-aware under RTL: the ProgressBar indeterminate bar now slides along the reading flow (right → left) instead of always physically left → right; the Switch thumb mirrors on toggle (off-thumb on the reading-start side, on-thumb on the reading-end side, per Material/iOS convention); and horizontal Layer enter animations (Popover/DropdownMenu/HoverCard/Selector placement start/end) now nudge in from the correct physical side. Vertical Layer entrances are unchanged (direction-neutral). LTR behavior is identical.
+@nynexman4464
diff --git a/packages/core/src/Layer/layerAnimations.stylex.ts b/packages/core/src/Layer/layerAnimations.stylex.ts
index 08cad5f287..fd16eb7d31 100644
--- a/packages/core/src/Layer/layerAnimations.stylex.ts
+++ b/packages/core/src/Layer/layerAnimations.stylex.ts
@@ -61,6 +61,27 @@ const enterStart = stylex.keyframes({
to: {opacity: 1, transform: 'translateX(0) scale(1)'},
});
+// RTL: the horizontal entrance nudge is a physical translateX, so it must
+// mirror under RTL — a layer on the inline-end/start side must slide in from
+// the correct physical side following the reading flow. Only the horizontal
+// (translateX) keyframes need mirroring; the vertical enterAbove/enterBelow
+// (translateY) entrances are direction-neutral and are left as-is.
+const enterEndRtl = stylex.keyframes({
+ from: {
+ opacity: 0,
+ transform: `translateX(${spacingVars['--spacing-2']}) scale(0.95)`,
+ },
+ to: {opacity: 1, transform: 'translateX(0) scale(1)'},
+});
+
+const enterStartRtl = stylex.keyframes({
+ from: {
+ opacity: 0,
+ transform: `translateX(calc(-1 * ${spacingVars['--spacing-2']})) scale(0.95)`,
+ },
+ to: {opacity: 1, transform: 'translateX(0) scale(1)'},
+});
+
const animationBase = {
animationDuration: durationVars['--duration-fast-max'],
animationTimingFunction: easeVars['--ease-standard'],
@@ -95,6 +116,7 @@ export const layerAnimations = stylex.create({
end: {
animationName: {
default: enterEnd,
+ ':is([dir="rtl"] *)': enterEndRtl,
'@media (prefers-reduced-motion: reduce)': 'none',
},
...animationBase,
@@ -102,6 +124,7 @@ export const layerAnimations = stylex.create({
start: {
animationName: {
default: enterStart,
+ ':is([dir="rtl"] *)': enterStartRtl,
'@media (prefers-reduced-motion: reduce)': 'none',
},
...animationBase,
diff --git a/packages/core/src/ProgressBar/ProgressBar.test.tsx b/packages/core/src/ProgressBar/ProgressBar.test.tsx
index e95bb57085..e53b1d26d6 100644
--- a/packages/core/src/ProgressBar/ProgressBar.test.tsx
+++ b/packages/core/src/ProgressBar/ProgressBar.test.tsx
@@ -242,5 +242,39 @@ describe('ProgressBar', () => {
unmount();
}
});
+
+ it('drives a direction-aware indeterminate slide (mirrored keyframe under RTL)', () => {
+ // StyleX injects the keyframes + the atomic rule that swaps the
+ // animation-name under `[dir="rtl"]`. Scan the injected CSS so we can
+ // assert the RTL branch exists without relying on jsdom animation.
+ function injectedCss(): string {
+ let out = '';
+ for (const sheet of Array.from(document.styleSheets)) {
+ try {
+ for (const rule of Array.from(sheet.cssRules)) {
+ out += rule.cssText + '\n';
+ }
+ } catch {
+ // ignore cross-origin sheets
+ }
+ }
+ out += Array.from(document.querySelectorAll('style'))
+ .map(s => s.textContent || '')
+ .join('\n');
+ return out;
+ }
+
+ render(<ProgressBar isIndeterminate label="Loading" />);
+ const css = injectedCss();
+ // LTR keyframe slides physically left → right (−100% → 250%).
+ expect(css).toMatch(/translateX\(-100%\)/);
+ expect(css).toMatch(/translateX\(250%\)/);
+ // RTL keyframe mirrors it (100% → −250%) so the bar travels along the
+ // reading flow (inline-start → inline-end, i.e. right → left).
+ expect(css).toMatch(/translateX\(100%\)/);
+ expect(css).toMatch(/translateX\(-250%\)/);
+ // The animation-name is swapped specifically under `[dir="rtl"]`.
+ expect(css).toMatch(/:is\(\[dir="rtl"\][^)]*\)[^{]*\{\s*animation-name:/);
+ });
});
});
diff --git a/packages/core/src/ProgressBar/ProgressBar.tsx b/packages/core/src/ProgressBar/ProgressBar.tsx
index bf7c436f62..2263847651 100644
--- a/packages/core/src/ProgressBar/ProgressBar.tsx
+++ b/packages/core/src/ProgressBar/ProgressBar.tsx
@@ -132,6 +132,18 @@ const indeterminateSlide = stylex.keyframes({
},
});
+// RTL: mirror the slide so the indeterminate bar travels along the reading
+// flow (inline-start → inline-end, i.e. right → left) instead of always
+// physically left → right. The magnitudes mirror the LTR keyframe.
+const indeterminateSlideRtl = stylex.keyframes({
+ '0%': {
+ transform: 'translateX(100%)',
+ },
+ '100%': {
+ transform: 'translateX(-250%)',
+ },
+});
+
// =============================================================================
// Styles
// =============================================================================
@@ -196,7 +208,10 @@ const styles = stylex.create({
height: '100%',
width: '40%',
borderRadius: radiusVars['--radius-full'],
- animationName: indeterminateSlide,
+ animationName: {
+ default: indeterminateSlide,
+ ':is([dir="rtl"] *)': indeterminateSlideRtl,
+ },
animationDuration: {
default: '1.5s',
'@media (prefers-reduced-motion: reduce)': '3s',
diff --git a/packages/core/src/Switch/Switch.test.tsx b/packages/core/src/Switch/Switch.test.tsx
index ae62e639cc..55676752d0 100644
--- a/packages/core/src/Switch/Switch.test.tsx
+++ b/packages/core/src/Switch/Switch.test.tsx
@@ -658,6 +658,58 @@ describe('Switch', () => {
});
});
+ describe('RTL thumb travel direction', () => {
+ // StyleX injects atomic rules into the document; scan them so we can assert
+ // the direction-aware transform without relying on jsdom to resolve the
+ // `:is([dir="rtl"] *)` descendant selector against computed style.
+ function injectedCss(): string {
+ let out = '';
+ for (const sheet of Array.from(document.styleSheets)) {
+ try {
+ for (const rule of Array.from(sheet.cssRules)) {
+ out += rule.cssText + '\n';
+ }
+ } catch {
+ // ignore cross-origin sheets
+ }
+ }
+ out += Array.from(document.querySelectorAll('style'))
+ .map(s => s.textContent || '')
+ .join('\n');
+ return out;
+ }
+
+ it('applies a distinct thumb style when on vs off (on-travel is wired)', () => {
+ const on = render(<Switch label="On" value={true} onChange={() => {}} />);
+ const off = render(
+ <Switch label="Off" value={false} onChange={() => {}} />,
+ );
+ const onThumb = on.container.querySelector(
+ '[class*="thumbOnSizeStyles"]',
+ );
+ const offThumb = off.container.querySelector(
+ '[class*="thumbOffSizeStyles"]',
+ );
+ expect(onThumb).not.toBeNull();
+ expect(offThumb).not.toBeNull();
+ expect(onThumb!.getAttribute('class')).not.toBe(
+ offThumb!.getAttribute('class'),
+ );
+ });
+
+ it('mirrors the on-state thumb travel under RTL (negative translateX)', () => {
+ render(<Switch label="Toggle" value={true} onChange={() => {}} />);
+ const css = injectedCss();
+ // LTR on-travel moves the thumb toward the physical right (positive px).
+ expect(css).toMatch(/transform:\s*translateX\(1[24]px\)/);
+ // RTL mirrors it: the on-thumb lands on the inline-end (physical left)
+ // side, so the travel flips sign, scoped to `[dir="rtl"]`.
+ expect(css).toMatch(
+ /:is\(\[dir="rtl"\][^)]*\)[^{]*\{\s*transform:\s*translateX\(-1[24]px\)/,
+ );
+ });
+ });
+
describe('rest forwarding', () => {
it('forwards data-testid, id, and aria-* to the root element', () => {
const {container} = render(
diff --git a/packages/core/src/Switch/Switch.tsx b/packages/core/src/Switch/Switch.tsx
index 40f6f1f076..7a697a26a4 100644
--- a/packages/core/src/Switch/Switch.tsx
+++ b/packages/core/src/Switch/Switch.tsx
@@ -99,12 +99,23 @@ const thumbOnSizeStyles = stylex.create({
sm: {
width: 16,
height: 16,
- transform: 'translateX(12px)',
+ // The thumb rests at the inline-start edge (flex-start, which flexbox
+ // already mirrors under RTL). The on-state travel toward the inline-end
+ // edge is a physical translateX, so it must flip sign under RTL — right
+ // in LTR, left in RTL — so the switch mirrors per convention (Material,
+ // iOS): off-thumb on the reading-start side, on-thumb on the reading-end.
+ transform: {
+ default: 'translateX(12px)',
+ ':is([dir="rtl"] *)': 'translateX(-12px)',
+ },
},
md: {
width: 20,
height: 20,
- transform: 'translateX(14px)',
+ transform: {
+ default: 'translateX(14px)',
+ ':is([dir="rtl"] *)': 'translateX(-14px)',
+ },
},
});