π OpenHands: AI-Driven Development
fix(ui): keep switch thumbs inside their tracks in right-to-left languages (#18551)
Engel Nyst61a3bd93e642
diff --git a/.pr/rtlswitch/after-arabic-analytics-on.png b/.pr/rtlswitch/after-arabic-analytics-on.pngnew file mode 100644index 0000000000..ecbbf9799dBinary files /dev/null and b/.pr/rtlswitch/after-arabic-analytics-on.png differdiff --git a/.pr/rtlswitch/after-arabic-checklist-on.png b/.pr/rtlswitch/after-arabic-checklist-on.pngnew file mode 100644index 0000000000..4a3d15d8b9Binary files /dev/null and b/.pr/rtlswitch/after-arabic-checklist-on.png differdiff --git a/.pr/rtlswitch/before-arabic-analytics-on.png b/.pr/rtlswitch/before-arabic-analytics-on.pngnew file mode 100644index 0000000000..a904f53f64Binary files /dev/null and b/.pr/rtlswitch/before-arabic-analytics-on.png differdiff --git a/.pr/rtlswitch/before-arabic-checklist-on.png b/.pr/rtlswitch/before-arabic-checklist-on.pngnew file mode 100644index 0000000000..14741f576aBinary files /dev/null and b/.pr/rtlswitch/before-arabic-checklist-on.png differdiff --git a/src/ui/toggle-switch.tsx b/src/ui/toggle-switch.tsxindex 64d85a8ce5..c9c1fbe7e0 100644--- a/src/ui/toggle-switch.tsx+++ b/src/ui/toggle-switch.tsx@@ -38,13 +38,15 @@ export function ToggleSwitchVisual({"inline-block rounded-full","transition-transform duration-200 ease-in-out motion-reduce:transition-none",compact ? "size-2" : "size-4",+ // The thumb starts at the inline start, which is the right edge in+ // RTL, so it travels towards the left there.enabled? compact- ? "translate-x-2.5 bg-base-secondary"- : "translate-x-5.25 bg-base-secondary"+ ? "translate-x-2.5 rtl:-translate-x-2.5 bg-base-secondary"+ : "translate-x-5.25 rtl:-translate-x-5.25 bg-base-secondary": compact? "translate-x-0 bg-muted"- : "translate-x-0.5 bg-muted",+ : "translate-x-0.5 rtl:-translate-x-0.5 bg-muted",)}/></span>diff --git a/tests/e2e/settings-responsive.spec.ts b/tests/e2e/settings-responsive.spec.tsindex 03d10c0d1b..832ba38a2a 100644--- a/tests/e2e/settings-responsive.spec.ts+++ b/tests/e2e/settings-responsive.spec.ts@@ -1,4 +1,4 @@-import { expect, test, type Page } from "@playwright/test";+import { expect, test, type Locator, type Page } from "@playwright/test";test.beforeEach(async ({ page }) => {await page.addInitScript(() => {@@ -102,3 +102,51 @@ for (const width of [390, 767, 768, 820, 1023, 1024, 1440]) {await expect(page.getByTestId("settings-navbar-desktop")).toBeVisible();});}++test("switch thumbs stay inside their tracks in a right-to-left language", async ({+ page,+}) => {+ await page.setViewportSize({ width: 1440, height: 1024 });+ await openMockPage(page, "/settings/app");+ await page.getByTestId("language-input").click();+ await page.getByRole("option", { name: "Arabic" }).click();+ await page.getByTestId("submit-button").click();+ await expect(page.locator("html")).toHaveAttribute("dir", "rtl");++ // Thumbs slide for 200ms after a toggle or a direction change, so wait+ // for the slide to finish before measuring.+ const thumbOverflow = (track: Locator) =>+ track.evaluate(async (element) => {+ const thumb = element.firstElementChild!;+ await Promise.all(thumb.getAnimations().map((slide) => slide.finished));+ const outer = element.getBoundingClientRect();+ const inner = thumb.getBoundingClientRect();+ return Math.max(outer.left - inner.left, inner.right - outer.right);+ });++ // Settings switches (`md`). The checklist switch starts on and the sound+ // switch off, so both thumb positions are covered.+ for (const [testId, checked] of [+ ["show-getting-started-checklist-switch", true],+ ["enable-sound-notifications-switch", false],+ ] as const) {+ const input = page.getByTestId(testId);+ if (checked) await expect(input).toBeChecked();+ else await expect(input).not.toBeChecked();+ const track = page+ .locator("label", { has: input })+ .locator("span[aria-hidden='true']");+ expect(await thumbOverflow(track)).toBeLessThanOrEqual(0);+ }++ // Menu-row switch (`sm`): hide older conversations, off and then on.+ await page.getByTestId("conversation-layouts-toggle").click();+ await page.getByTestId("advanced-options-row").click();+ const hideOlder = page.getByTestId("toggle-older-conversations");+ const compactTrack = hideOlder.locator(":scope > span[aria-hidden='true']");+ for (const checked of ["false", "true"]) {+ if (checked === "true") await compactTrack.click();+ await expect(hideOlder).toHaveAttribute("aria-checked", checked);+ expect(await thumbOverflow(compactTrack)).toBeLessThanOrEqual(0);+ }+});