Skip to content

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

TypeScript

fix(rtl-audit): D2 and D3 fail when a relationship keeps its LTR order in RTL (#9342)

Cindy Zhangafc58e1993c3
diff --git a/.github/scripts/rtl-audit-coverage.test.mjs b/.github/scripts/rtl-audit-coverage.test.mjs
index ab5301a6e8..7cb7ccfdad 100644
--- a/.github/scripts/rtl-audit-coverage.test.mjs
+++ b/.github/scripts/rtl-audit-coverage.test.mjs
@@ -27,6 +27,7 @@ import {
glyphRendersOnBlockAxis,
isUnchangedBlockAxisPair,
finishFiniteAnimations,
+ gradeDirectionalPair,
gradePositionedPair,
orderD1StoryCandidates,
resolveD1Applicability,
@@ -1304,3 +1305,18 @@ describe('resolveFilterRoutes (filters resolve through the Storybook index)', ()
expect(resolve([]).routes).toBe(routes);
});
});
+
+describe('gradeDirectionalPair (D2 order, D3 scroll direction)', () => {
+ it('passes a relationship that holds in LTR and reverses in RTL', () => {
+ expect(gradeDirectionalPair(true, true)).toBe('pass');
+ });
+
+ it('fails a relationship that keeps its LTR physical order in RTL', () => {
+ expect(gradeDirectionalPair(true, false)).toBe('fail');
+ });
+
+ it('fails a relationship already wrong in LTR, or wrong in both', () => {
+ expect(gradeDirectionalPair(false, true)).toBe('fail');
+ expect(gradeDirectionalPair(false, false)).toBe('fail');
+ });
+});
diff --git a/apps/storybook/rtl-audit/rtl-audit-coverage.mjs b/apps/storybook/rtl-audit/rtl-audit-coverage.mjs
index fb7a6380db..27e742c8ab 100644
--- a/apps/storybook/rtl-audit/rtl-audit-coverage.mjs
+++ b/apps/storybook/rtl-audit/rtl-audit-coverage.mjs
@@ -401,6 +401,16 @@ export function validateStoryRtlAuditParameters(value, storyId) {
return result;
}
+/**
+ * Grade a curated order (D2) or scroll-direction (D3) pair. The relationship
+ * must hold in LTR and reverse in RTL. A relationship that keeps its LTR
+ * physical order in RTL is the RTL defect these checks exist for, so it fails
+ * rather than grading `partial` (INV3); so does one already wrong in LTR.
+ */
+export function gradeDirectionalPair(ltrOk, rtlOk) {
+ return ltrOk && rtlOk ? 'pass' : 'fail';
+}
+
// rtlAudit.D5 declares a region whose positioned elements stay physical
// (DR5); it never turns D5 off for the story.
function validatePhysicalPosition(value, storyId) {
diff --git a/apps/storybook/rtl-audit/rtl-audit.mjs b/apps/storybook/rtl-audit/rtl-audit.mjs
index 74e6b7b41d..1b718203ba 100644
--- a/apps/storybook/rtl-audit/rtl-audit.mjs
+++ b/apps/storybook/rtl-audit/rtl-audit.mjs
@@ -73,6 +73,7 @@ import {
d1GlyphKey,
d1PairKey,
glyphRendersOnBlockAxis,
+ gradeDirectionalPair,
gradePositionedPair,
isUnchangedBlockAxisPair,
orderD1StoryCandidates,
@@ -940,7 +941,7 @@ async function checkD2(page, port, t, card) {
const pR = await boxOf(page, prev), nR = await boxOf(page, next);
if (!pL || !nL || !pR || !nR) { card.dims.D2 = 'N-A'; card.notes.push('D2: prev/next not found'); return; }
const ltrOk = pL.cx < nL.cx, rtlOk = pR.cx > nR.cx;
- card.dims.D2 = ltrOk && rtlOk ? 'pass' : ltrOk || rtlOk ? 'partial' : 'fail';
+ card.dims.D2 = gradeDirectionalPair(ltrOk, rtlOk);
card.notes.push(`D2 prev/next cx: LTR ${pL.cx.toFixed(0)}<${nL.cx.toFixed(0)}=${ltrOk}; RTL ${pR.cx.toFixed(0)}>${nR.cx.toFixed(0)}=${rtlOk}`);
}
async function checkD3Scroll(page, port, t, card) {
@@ -957,7 +958,7 @@ async function checkD3Scroll(page, port, t, card) {
const dL = await run(false), dR = await run(true);
if (dL == null || dR == null) { card.dims.D3 = 'N-A'; card.notes.push('D3: scroller/next not found'); return; }
const ltrOk = dL > 1, rtlOk = dR < -1;
- card.dims.D3 = ltrOk && rtlOk ? 'pass' : ltrOk || rtlOk ? 'partial' : 'fail';
+ card.dims.D3 = gradeDirectionalPair(ltrOk, rtlOk);
card.notes.push(`D3 scroll delta on next: LTR ${dL.toFixed(0)} (>0=${ltrOk}); RTL ${dR.toFixed(0)} (<0=${rtlOk})`);
}
async function checkD4(page, port, t, card) {