Skip to content

Commit ccdfe62

Browse files
fix(components): in a right-to-left language the desktop sidebar sits beside the page instead of over its header (#38213)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoNZP1tN1FWjFR4ejvdtt1bb)_ Fixes #37914 repo:objectstack#3 · os-tesla · session_01L9qibvkagpUt9LtVz1U4MM Clause-②: no Metadata-protocol: none ## 维护者速读 - 界面语言是阿拉伯语时,桌面上的侧边栏改到右边、紧挨页面内容,不再从左边盖住页面末端;页头的按钮、帮助、评论和「问 AI」都看得见、点得到。收起、悬停浮出、拖宽和无页头页面上的展开按钮也都跟着换到右边。 - 替用阿拉伯语界面的桌面用户解决:每个应用的每个页面,页面左边 256 像素被侧边栏挡住,右边却空着一条。 - 只改侧边栏放在哪一边,从左到右的语言一个像素不变(逐项量过);出问题最多是阿拉伯语下侧边栏位置不对,可以直接撤回。 - 无 ## What changes - `ui/packages/components/src/ui/sidebar.tsx` (shadcn primitive, declared patches only): the desktop panel, its divider and the edge rail are placed with logical insets. `side="left"` is the document's inline start, `side="right"` its end, as the in-flow gap already was: `left-0`/`right-0` and the collapsed offsets become `start-*`/`end-*`, the divider `border-e`/`border-s`, the rail's offsets and hover line `start-*`/`end-*`, its half-width shift gets `rtl:translate-x-1/2`, and its resize cursors get `rtl:` mirrors (expanded and collapsed). In a left-to-right document every logical inset computes to the physical one it replaces. - `ui/scripts/shadcn-local-patches.mjs`: a new declared family, `sidebarLogicalInsetPatches` (objectstack#37914: divider, rail, the two cursor lines), anchored on `scripts/__tests__/fixtures/shadcn-registry/sidebar.registry.txt`, markers = the whole patched strings. The offcanvas family (objectui#11464) now writes its panel offsets and rail edge offsets in the logical spelling; its doc block says how. `packages/components/shadcn-components.json` `localEdits` names the new family. - `ui/packages/app-shell/src/layout/consoleSidebarRail.ts`: `SIDEBAR_EDGE_ZONE` (the strip that floats a hidden sidebar) is `start-0`; `RAIL_OVERLAY_PANEL` is `start-2` and `RAIL_HIDDEN_PANEL` parks with `start-[...]`. New `isRightToLeft(el)` (nearest `dir` says `rtl`). `pointerOnFloat`, which decides whether a hover-opened float folds, measured its margin and side from the window's left edge; it now reads the start edge, so in RTL a pointer over the page folds the float (this site was not in the pre-claim list; it is in the claimed file and its premise, panel at the left, is what the primitive change makes false). - `ui/packages/app-shell/src/layout/SidebarWidthHandle.tsx`: the handle is `-end-1`; a drag and the arrow keys toward the page widen the sidebar in either direction (the drag's sign and the arrow step flip in RTL). - `ui/packages/app-shell/src/layout/ShellPageActions.tsx`: `ShellSidebarExpandFallback` is `start-2`, opposite the assistant's fallback (`end-2`). On main in RTL both sat in the top-left corner and overlapped (readings below). - Changeset `.changeset/37914-sidebar-right-to-left.md`: `@object-ui/components` patch, `@object-ui/app-shell` patch. ## Tests - `ui/e2e/sidebar-offcanvas-geometry.spec.ts` (Chromium, real primitive source, real Tailwind): new describe `the sidebar in a right-to-left document`. (1) expanded `offcanvas` and `icon` in RTL: panel 1024..1280, page 0..1024, gap 256, divider on the left. (2) all eight primitive cases (offcanvas/icon × left/right × expanded/collapsed): the RTL panel, page, gap, divider, rail box and rail cursor equal the LTR reading mirrored. The six existing LTR cases are unchanged and green. - `ui/scripts/__tests__/shadcn-local-patches.test.ts`: the new family's ids; each replacement read back through the LTR mapping keeps upstream's classes and adds only `rtl:` mirrors; no physical inset is left between the desktop gap and `SidebarRail`; the offcanvas family's invariant reads the logical spelling back; the sidebar carries six families. - `ui/packages/app-shell/src/layout/__tests__/SidebarWidthHandle.rightToLeft-37914.test.tsx` (new): drag and arrow keys in LTR (control) and RTL. - Updated pins that named the old classes: `UnifiedSidebar.hiddenCollapse-35062.test.tsx` (the float card is `start-2`), `sidebar-side-registration-11070.test.tsx` (`end-0`/`start-0`; also a module-top `@object-ui/react-runtime` import, which `check:test-source-alias` asks of an edited test that reaches it). <details><summary>Ablation (at 400674f, sidebar.tsx put back to main's bytes, then restored)</summary> - `sidebar-offcanvas-geometry.spec.ts`: the two RTL tests fail (panel 0..256 where 1024..1280 is expected; divider `["0px","1px"]` where `["1px","0px"]`), the six LTR tests pass. - `shadcn-local-patches.test.ts`: 2 fail (`sidebar declares the logical-inset patches`, `sidebar.tsx carries its declared patches`), 86 pass. - `SidebarWidthHandle.tsx` put back to main's bytes: the two RTL cases fail, the two LTR cases pass. </details> <details><summary>Real console readings, before (main's four source files) and after (400674f source; the later commits change tests only)</summary> Showcase app booted from this tree (`objectstack dev --seed-admin`), the console served from `ui/` source by Vite and pointed at it, Chromium 1280×800, `objectui-locale=ar` (and `en` as the control). Script and full readings: the card thread's project files (`console-rtl/measure.js`, `readings-400674f7.txt`). | Reading (Arabic) | Before | After | |---|---|---| | List page: panel / main | 0..256 / 0..1024 | 1024..1280 / 0..1024 | | List page: header group 16..48, overlap with panel | 32 px | 0 | | Record page: panel / main | 0..256 / 0..1024 | 1024..1280 / 0..1024 | | Record page: header group 8..40, overlap; help button hit-test | 32 px; covered | 0; clickable | | Dashboard: panel / main | 0..256 / 0..1024 | 1024..1280 / 0..1024 | | Dashboard: header group 24..297, overlap | 232 px | 0 | | Resize edge; a 40 px drag toward the page | 251..259; 256→296 (drag +40) | 1021..1029; 256→296 (drag −40) | | Hidden: edge strip; parked card | 0..8; −288..−32 | 1272..1280; 1312..1568 | | Float (hover on the strip): card | 8..264 | 1016..1272 | | Float, pointer moved to x 640: card | parked again | parked again | | Search page, collapsed: expand button / assistant button | 8..36 / 8..186 (overlap) | 1244..1272 / 8..186 | - On main in Arabic the page header itself is drawn above the panel on the list and dashboard pages (its buttons hit-test as clickable), but the panel covers the first 256 px of the content under it (the dashboard's first KPI card and first chart are hidden) and the sidebar's own top row is under the page header; on the record page the header's help button is under the panel. - English, before and after: identical readings in every row (panel 0..256, main 256..1280, handle 251..259, strip 0..8, card 8..264, expand 8..36, assistant 1186..1272). - FIXTURE in the search-page row only: the runtime here serves no agent, so the assistant fallback would not draw; one stub agent in the catalogue response turns it on for that reading. </details> ## Acceptance notes - Phone: the drawer (`Sheet side="left"`) still slides in from the left in Arabic, and the drawer's swipe gesture (`UnifiedSidebar.tsx`, the touch handlers) reads `clientX` in the left-to-right sense. Both are phone-only and out of this card's scope (seat's claim); not measured. - `data-side` keeps the words `left`/`right`; they now mean the inline start and end. No consumer in the tree passes `side="right"` to the console sidebar today. ## Verification Read first (by risk): 1. `ui/scripts/shadcn-local-patches.mjs`: the offcanvas family's two offset replacements and the new `sidebarLogicalInsetPatches`, against `sidebar.tsx` lines 262-268 and 328-333. 2. `consoleSidebarRail.ts` `pointerOnFloat`: the float-away test in RTL. 3. `SidebarWidthHandle.tsx`: `toward` and the arrow `step`. Two-minute check: switch the console language to Arabic at a desktop width and open any list page: the sidebar is on the right and the page header's buttons on the left are all visible. <details><summary>Local gates at 7bc711b (base origin/main 7605e0c; merges cleanly onto e3bdc74)</summary> - `node scripts/pm/dispatch-gates.mjs --commands`: 42 families derived; all 42 run, each with its exit code (`gates-ran-7bc711bf.list` in the card thread's project files). 40 ran at 400674f and exited 0; `pnpm check:test-source-alias` and `pnpm --dir ui exec vitest run scripts/` exited 1 there (the first was a real finding in an edited test, fixed in 7bc711b; the second was killed by the container's memory limit while another run shared it) and both exit 0 at 7bc711b. `--ran`: "42 run, 0 NOT-MEASURED (a DERIVED zero)". - `pnpm --filter @object-ui/components type-check`: exit 0. `pnpm --filter @object-ui/app-shell type-check`: exit 0. - `vitest run packages/app-shell/src/layout/` (175 files): 1 failure at 400674f (`UnifiedSidebar.hiddenCollapse-35062`, the `left-2` pin), fixed in 08ef3cc; that file 33/33 after. The 60 test files under `packages/components` and `packages/layout` that mention the sidebar: 638/639 at 400674f, the one failure (`sidebar-side-registration-11070`, the `right-0` pin) fixed in 08ef3cc, 5/5 after. The packages' full suites: CI. - `ui/e2e/sidebar-offcanvas-geometry.spec.ts` in Chromium: 8/8. - `overlap-check.mjs`: `VERDICT clean exit 0` against origin/main e3bdc74, 0 open PR heads share a file. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibvkagpUt9LtVz1U4MM)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent fd06b7a commit ccdfe62

12 files changed

Lines changed: 374 additions & 52 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/components': patch
3+
'@object-ui/app-shell': patch
4+
---
5+
6+
fix(components): in a right-to-left language the desktop sidebar sits beside the page instead of over its header
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
In Arabic (the console sets `dir="rtl"` on the page) the desktop sidebar's gap moved to the right while its fixed panel stayed on the left, so the panel covered the end of every page, where a right-to-left page header keeps its buttons: the page's own actions, help, comments and Ask AI entry could not be reached. The sidebar primitive now places its panel, its divider and its edge rail with logical insets, so `side="left"` is the inline start of the document (the right edge in Arabic) and `side="right"` its end. The edits are declared as the `sidebarLogicalInsetPatches` shadcn local-patch family, with the offcanvas family's offsets written the same way, so a registry sync keeps them.
12+
13+
`@object-ui/app-shell`: the console sidebar's own anchors follow it. The edge strip that floats a hidden sidebar, the floating card and its parked position, the resize edge and the expand button on pages with no header sit at the inline start, and the resize edge reads a drag and the arrow keys toward the page as widening in either direction. A floating menu folds when the pointer leaves it on either side.
14+
15+
Left-to-right languages are unchanged: every logical inset computes to the physical one it replaces.

‎ui/e2e/sidebar-offcanvas-geometry.spec.ts‎

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ import { uiRoot } from '../scripts/ui-root.mjs';
6767
* The workspace packages are stubbed rather than resolved because this lane
6868
* builds no workspace `dist/`, and their `exports` point there.
6969
*
70+
* The same cases are also read in a right-to-left document (objectstack#37914,
71+
* the last describe block): there every reading must be the left-to-right one
72+
* mirrored across the viewport's centre line.
73+
*
7074
* Static markup carries no client effects, so `useIsMobile()` reads desktop and
7175
* the mobile `Sheet` branch is out of scope: this patch does not touch it, and
7276
* below `md` the desktop form is `hidden` anyway.
@@ -271,15 +275,23 @@ interface Reading {
271275
cssLeft: string;
272276
cssRight: string;
273277
afterLeft: string;
278+
cursor: string;
274279
};
280+
/** The panel's divider widths, `[left, right]`. */
281+
border: [string, string];
275282
}
276283

277-
async function measure(page: Page, markup: string, css: string): Promise<Reading> {
284+
async function measure(page: Page, markup: string, css: string, dir: 'ltr' | 'rtl' = 'ltr'): Promise<Reading> {
278285
await page.setViewportSize(VIEWPORT);
279286
// One document, the stylesheet ahead of the markup, so the first style
280287
// resolution is the styled one and no `transition-*` utility animates a
281-
// change while the reading is taken.
282-
await page.setContent(`<style>${css}</style>${markup}`, { waitUntil: 'load' });
288+
// change while the reading is taken. A right-to-left document carries `dir`
289+
// on `<html>` from the first parse, where the i18n provider puts it.
290+
const html =
291+
dir === 'rtl'
292+
? `<html dir="rtl"><head><style>${css}</style></head><body>${markup}</body></html>`
293+
: `<style>${css}</style>${markup}`;
294+
await page.setContent(html, { waitUntil: 'load' });
283295
await page.waitForFunction(
284296
() => {
285297
const panel = document.querySelector('[data-sidebar="sidebar"]')?.parentElement;
@@ -321,8 +333,10 @@ async function measure(page: Page, markup: string, css: string): Promise<Reading
321333
cssLeft: railStyle.left,
322334
cssRight: railStyle.right,
323335
afterLeft: getComputedStyle(rail, '::after').left,
336+
cursor: railStyle.cursor,
324337
}
325338
: null,
339+
border: [getComputedStyle(panel).borderLeftWidth, getComputedStyle(panel).borderRightWidth] as [string, string],
326340
};
327341
});
328342
}
@@ -431,3 +445,48 @@ test.describe('the sidebar offcanvas form in Chromium (objectui#11464)', () => {
431445
expect(collapsed.page?.left).toBe(0);
432446
});
433447
});
448+
449+
/** A box reflected across the viewport's vertical centre line. */
450+
const mirror = (b: Box): Box => ({ left: VIEWPORT.width - b.right, right: VIEWPORT.width - b.left, width: b.width });
451+
452+
/** The cursor a mirrored rail shows: west and east swap. */
453+
const mirrorCursor = (c: string) => (c === 'w-resize' ? 'e-resize' : c === 'e-resize' ? 'w-resize' : c);
454+
455+
/**
456+
* objectstack#37914: in a right-to-left document (`dir="rtl"` on `<html>`, set
457+
* by the i18n provider for Arabic) the flex row is reversed, so the gap moves
458+
* to the right. With physical `left-0` the fixed panel stayed on the left, over
459+
* the end of the page, where a right-to-left page header keeps its buttons:
460+
* measured on main, the panel at 0..256 over a page laid out at 0..1024. The
461+
* primitive now places the panel, its divider and the rail with logical insets
462+
* (`sidebarLogicalInsetPatches` in `scripts/shadcn-local-patches.mjs`).
463+
*/
464+
test.describe('the sidebar in a right-to-left document (objectstack#37914)', () => {
465+
test('an expanded sidebar sits beside the page at the right edge, not over the page at the left', async ({ page }) => {
466+
for (const collapsible of ['offcanvas', 'icon'] as const) {
467+
const rtl = await measure(page, markup.primitive[`${collapsible}-left-expanded`], css, 'rtl');
468+
expect.soft({ panel: rtl.panel, page: rtl.page, gap: rtl.gapWidth }, collapsible).toEqual({
469+
panel: { left: VIEWPORT.width - SIDEBAR_PX, right: VIEWPORT.width, width: SIDEBAR_PX },
470+
page: { left: 0, right: VIEWPORT.width - SIDEBAR_PX, width: VIEWPORT.width - SIDEBAR_PX },
471+
gap: SIDEBAR_PX,
472+
});
473+
// The divider faces the page.
474+
expect.soft(rtl.border, `${collapsible}: the divider`).toEqual(['1px', '0px']);
475+
}
476+
});
477+
478+
test('every reading is the left-to-right one mirrored, on either side, expanded or collapsed', async ({ page }) => {
479+
for (const key of Object.keys(markup.primitive) as Array<keyof Markup['primitive']>) {
480+
const ltr = await measure(page, markup.primitive[key], css, 'ltr');
481+
const rtl = await measure(page, markup.primitive[key], css, 'rtl');
482+
expect.soft(rtl.panel, `${key}: the panel`).toEqual(mirror(ltr.panel));
483+
expect.soft(rtl.gapWidth, `${key}: the gap`).toBe(ltr.gapWidth);
484+
expect.soft(rtl.page, `${key}: the page`).toEqual(ltr.page ? mirror(ltr.page) : null);
485+
expect.soft(rtl.border, `${key}: the divider`).toEqual([ltr.border[1], ltr.border[0]]);
486+
expect.soft(rtl.rail?.box, `${key}: the rail`).toEqual(ltr.rail ? mirror(ltr.rail.box) : undefined);
487+
expect.soft(rtl.rail?.cursor, `${key}: the rail's cursor`).toBe(
488+
ltr.rail ? mirrorCursor(ltr.rail.cursor) : undefined,
489+
);
490+
}
491+
});
492+
});

‎ui/packages/app-shell/src/layout/ShellPageActions.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ const noSubscription = () => () => {};
184184
/**
185185
* The expand button for a route whose page draws none of the shell's headers
186186
* (search results, a component page, the app editor): pinned at the content's
187-
* top-left corner while the sidebar is collapsed. It takes no room of its own.
187+
* top start corner (top-left; top-right in a right-to-left language, the
188+
* sidebar's side, objectstack#37914) while the sidebar is collapsed, opposite
189+
* the assistant's fallback below. It takes no room of its own.
188190
*/
189191
export function ShellSidebarExpandFallback() {
190192
const registry = React.useContext(ExpandHeaderRegistryContext);
@@ -197,7 +199,7 @@ export function ShellSidebarExpandFallback() {
197199
if (!registry || headers > 0 || isMobile || open) return null;
198200
return (
199201
<div className="sticky top-0 z-20 h-0" data-testid="shell-sidebar-expand-fallback">
200-
<SidebarExpandTrigger className="absolute left-2 top-2 bg-background/80 backdrop-blur" />
202+
<SidebarExpandTrigger className="absolute start-2 top-2 bg-background/80 backdrop-blur" />
201203
</div>
202204
);
203205
}

‎ui/packages/app-shell/src/layout/SidebarWidthHandle.tsx‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
22

33
/**
4-
* SidebarWidthHandle — the docked console sidebar's right edge, which resizes
5-
* it (objectstack#36227, as Attio): dragged with the pointer between
4+
* SidebarWidthHandle — the docked console sidebar's page-facing edge (its
5+
* right edge, or its left edge in a right-to-left language, objectstack#37914),
6+
* which resizes it (objectstack#36227, as Attio): dragged with the pointer between
67
* {@link CONSOLE_SIDEBAR_MIN_WIDTH} and {@link CONSOLE_SIDEBAR_MAX_WIDTH}, or
78
* moved with ← → (Home / End to either end). A double-click comes back to
89
* {@link CONSOLE_EXPANDED_SIDEBAR_WIDTH}. `onPreview` follows a drag;
@@ -17,6 +18,7 @@ import {
1718
CONSOLE_SIDEBAR_MAX_WIDTH,
1819
CONSOLE_SIDEBAR_MIN_WIDTH,
1920
clampConsoleSidebarWidth,
21+
isRightToLeft,
2022
} from './consoleSidebarRail.js';
2123

2224
/** How far one arrow-key press moves the sidebar's edge, in CSS pixels. */
@@ -33,7 +35,9 @@ export interface SidebarWidthHandleProps {
3335

3436
export function SidebarWidthHandle({ width, onPreview, onCommit }: SidebarWidthHandleProps) {
3537
const { t } = useObjectTranslation();
36-
const drag = React.useRef<{ x: number; width: number; last: number } | null>(null);
38+
// `toward` is +1 when a move to the right widens the sidebar (left to right),
39+
// -1 when it narrows it (right to left, where the sidebar sits on the right).
40+
const drag = React.useRef<{ x: number; width: number; last: number; toward: 1 | -1 } | null>(null);
3741

3842
const end = (commit: boolean) => {
3943
const start = drag.current;
@@ -73,19 +77,24 @@ export function SidebarWidthHandle({ width, onPreview, onCommit }: SidebarWidthH
7377
aria-valuemax={CONSOLE_SIDEBAR_MAX_WIDTH}
7478
tabIndex={0}
7579
data-testid="console-sidebar-resize"
76-
className="group/resize absolute inset-y-0 -right-1 z-20 flex w-2 cursor-col-resize touch-none justify-center focus-visible:outline-none"
80+
className="group/resize absolute inset-y-0 -end-1 z-20 flex w-2 cursor-col-resize touch-none justify-center focus-visible:outline-none"
7781
onPointerDown={(event) => {
7882
if (event.button !== 0) return;
7983
event.preventDefault();
8084
event.currentTarget.setPointerCapture?.(event.pointerId);
81-
drag.current = { x: event.clientX, width, last: width };
85+
drag.current = {
86+
x: event.clientX,
87+
width,
88+
last: width,
89+
toward: isRightToLeft(event.currentTarget) ? -1 : 1,
90+
};
8291
document.body.style.setProperty('cursor', 'col-resize');
8392
document.body.style.setProperty('user-select', 'none');
8493
}}
8594
onPointerMove={(event) => {
8695
const start = drag.current;
8796
if (!start) return;
88-
start.last = clampConsoleSidebarWidth(start.width + event.clientX - start.x);
97+
start.last = clampConsoleSidebarWidth(start.width + start.toward * (event.clientX - start.x));
8998
onPreview(start.last);
9099
}}
91100
onPointerUp={(event) => {
@@ -98,9 +107,12 @@ export function SidebarWidthHandle({ width, onPreview, onCommit }: SidebarWidthH
98107
onCommit(CONSOLE_EXPANDED_SIDEBAR_WIDTH);
99108
}}
100109
onKeyDown={(event) => {
110+
// The arrow toward the page widens the sidebar: → in a left-to-right
111+
// language, ← in a right-to-left one, where the edge faces left.
112+
const step = isRightToLeft(event.currentTarget) ? -SIDEBAR_WIDTH_KEY_STEP : SIDEBAR_WIDTH_KEY_STEP;
101113
const next =
102-
event.key === 'ArrowLeft' ? width - SIDEBAR_WIDTH_KEY_STEP
103-
: event.key === 'ArrowRight' ? width + SIDEBAR_WIDTH_KEY_STEP
114+
event.key === 'ArrowLeft' ? width - step
115+
: event.key === 'ArrowRight' ? width + step
104116
: event.key === 'Home' ? CONSOLE_SIDEBAR_MIN_WIDTH
105117
: event.key === 'End' ? CONSOLE_SIDEBAR_MAX_WIDTH
106118
: null;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#37914 — in a right-to-left language the docked sidebar sits at
5+
* the window's right edge (the primitive places it at the inline start), so
6+
* its resize edge faces left: a drag to the left and the ← key widen it, a
7+
* drag to the right and the → key narrow it. Left to right is unchanged and
8+
* is the control here. Where the edge and the shell's other sidebar anchors
9+
* are drawn is measured in Chromium by `e2e/sidebar-offcanvas-geometry.spec.ts`.
10+
*/
11+
12+
import { afterEach, describe, expect, it } from 'vitest';
13+
import * as React from 'react';
14+
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
15+
import { SidebarWidthHandle, SIDEBAR_WIDTH_KEY_STEP } from '../SidebarWidthHandle';
16+
import { isRightToLeft } from '../consoleSidebarRail';
17+
18+
function Harness({ initial = 256 }: { initial?: number }) {
19+
const [width, setWidth] = React.useState(initial);
20+
const [preview, setPreview] = React.useState<number | null>(null);
21+
return (
22+
<div data-testid="width" data-width={preview ?? width}>
23+
<SidebarWidthHandle width={preview ?? width} onPreview={setPreview} onCommit={setWidth} />
24+
</div>
25+
);
26+
}
27+
28+
const handle = () => screen.getByTestId('console-sidebar-resize');
29+
const width = () => Number(screen.getByTestId('width').getAttribute('data-width'));
30+
31+
function drag(dx: number) {
32+
fireEvent.pointerDown(handle(), { button: 0, clientX: 600, pointerId: 1 });
33+
fireEvent.pointerMove(handle(), { clientX: 600 + dx, pointerId: 1 });
34+
fireEvent.pointerUp(handle(), { clientX: 600 + dx, pointerId: 1 });
35+
}
36+
37+
afterEach(() => {
38+
cleanup();
39+
document.documentElement.removeAttribute('dir');
40+
});
41+
42+
describe.each([
43+
{ dir: 'ltr', widen: 1 },
44+
{ dir: 'rtl', widen: -1 },
45+
] as const)('the sidebar resize edge in a $dir document (objectstack#37914)', ({ dir, widen }) => {
46+
it('a drag toward the page widens the sidebar and a drag away narrows it', () => {
47+
document.documentElement.setAttribute('dir', dir);
48+
render(<Harness />);
49+
expect(isRightToLeft(handle())).toBe(dir === 'rtl');
50+
drag(widen * 40);
51+
expect(width()).toBe(296);
52+
drag(-widen * 80);
53+
expect(width()).toBe(216);
54+
});
55+
56+
it('the arrow key toward the page widens the sidebar', () => {
57+
document.documentElement.setAttribute('dir', dir);
58+
render(<Harness />);
59+
const towardPage = widen === 1 ? 'ArrowRight' : 'ArrowLeft';
60+
const awayFromPage = widen === 1 ? 'ArrowLeft' : 'ArrowRight';
61+
fireEvent.keyDown(handle(), { key: towardPage });
62+
expect(width()).toBe(256 + SIDEBAR_WIDTH_KEY_STEP);
63+
fireEvent.keyDown(handle(), { key: awayFromPage });
64+
fireEvent.keyDown(handle(), { key: awayFromPage });
65+
expect(width()).toBe(256 - SIDEBAR_WIDTH_KEY_STEP);
66+
});
67+
});

‎ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.hiddenCollapse-35062.test.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,9 +833,11 @@ describe('the docked sidebar’s right edge resizes it, and the float takes the
833833
expect(resizeHandle(), 'the float is not resized').toBeNull();
834834
expect(frameWidth()).toBe('300px');
835835
for (const token of RAIL_OVERLAY_PANEL.split(' ')) expect(tokens(panel())).toContain(token);
836-
// A card: off the window's edges, rounded, with a shadow.
837-
expect(tokens(panel())).toEqual(expect.arrayContaining(['inset-y-2', 'left-2', 'rounded-lg', 'shadow-xl']));
836+
// A card: off the window's edges, rounded, with a shadow. Its offset is
837+
// from the window's inline start, the primitive's own edge (objectstack#37914).
838+
expect(tokens(panel())).toEqual(expect.arrayContaining(['inset-y-2', 'start-2', 'rounded-lg', 'shadow-xl']));
838839
expect(tokens(panel())).not.toContain('inset-y-0');
840+
expect(tokens(panel())).not.toContain('start-0');
839841
expect(tokens(panel())).not.toContain('left-0');
840842
});
841843

‎ui/packages/app-shell/src/layout/consoleSidebarRail.ts‎

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,15 @@ export const SIDEBAR_FLOAT_OPEN_DELAY_MS = 200;
329329
export const SIDEBAR_FLOAT_CLOSE_DELAY_MS = 150;
330330

331331
/**
332-
* The left-edge strip drawn while the sidebar is hidden, which floats the
333-
* menu: 8 px (`w-2`), the strip the sidebar primitive's own `SidebarRail`
334-
* leaves inside the viewport beside a collapsed `offcanvas` sidebar (its `w-4`
335-
* strip moved `-right-2` past the panel's edge). Fixed, above the page; the
336-
* call site places it where it places the sidebar.
332+
* The edge strip drawn while the sidebar is hidden, which floats the menu:
333+
* 8 px (`w-2`), the strip the sidebar primitive's own `SidebarRail` leaves
334+
* inside the viewport beside a collapsed `offcanvas` sidebar (its `w-4` strip
335+
* moved `-end-2` past the panel's edge). Fixed, above the page, at the
336+
* window's inline start (`start-0`): the left edge, or the right edge in a
337+
* right-to-left language, where the primitive draws the panel
338+
* (objectstack#37914). The call site places it where it places the sidebar.
337339
*/
338-
export const SIDEBAR_EDGE_ZONE = 'fixed left-0 z-40 w-2';
340+
export const SIDEBAR_EDGE_ZONE = 'fixed start-0 z-40 w-2';
339341

340342
/**
341343
* The frame's class while the menu floats: the sidebar's gap (the in-flow box
@@ -349,18 +351,30 @@ export const RAIL_OVERLAY_FRAME_NO_GAP = '[&>[data-collapsible=offcanvas]>div:fi
349351

350352
/**
351353
* The panel's classes while the menu floats: a card above the page, 8 px off
352-
* the window's left, top and bottom edges, with rounded corners, a border and
353-
* a shadow, and nothing dimmed under it (objectstack#36227, as Attio).
354+
* the window's start (left, or right in a right-to-left language), top and
355+
* bottom edges, with rounded corners, a border and a shadow, and nothing
356+
* dimmed under it (objectstack#36227, as Attio). Logical like the primitive's
357+
* own `start-0` (objectstack#37914), which this replaces.
354358
*/
355359
export const RAIL_OVERLAY_PANEL =
356-
'z-40 inset-y-2 left-2 h-auto overflow-hidden rounded-lg border border-sidebar-border shadow-xl';
360+
'z-40 inset-y-2 start-2 h-auto overflow-hidden rounded-lg border border-sidebar-border shadow-xl';
357361

358362
/**
359363
* The panel's classes while the sidebar is hidden: the float's card, parked
360-
* past the window's left edge by its own width and 2 rem more, so its shadow
364+
* past the window's start edge by its own width and 2 rem more, so its shadow
361365
* does not show at the edge. The card keeps its shape as it slides in and out.
362366
*/
363-
export const RAIL_HIDDEN_PANEL = `${RAIL_OVERLAY_PANEL} group-data-[state=collapsed]:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1-2rem)]`;
367+
export const RAIL_HIDDEN_PANEL = `${RAIL_OVERLAY_PANEL} group-data-[state=collapsed]:group-data-[collapsible=offcanvas]:start-[calc(var(--sidebar-width)*-1-2rem)]`;
368+
369+
/**
370+
* Whether `el` is laid out right to left: the nearest `dir` above it (the i18n
371+
* provider sets it on `<html>`) says `rtl`. The sidebar then sits at the
372+
* window's right edge, so a pointer measured in `clientX` reads the other way
373+
* round (objectstack#37914).
374+
*/
375+
export function isRightToLeft(el: Element | null | undefined): boolean {
376+
return el?.closest('[dir]')?.getAttribute('dir') === 'rtl';
377+
}
364378

365379
/**
366380
* The frame's class while the reader drags the sidebar's edge: the gap and the
@@ -400,8 +414,12 @@ function pointerOnFloat(root: HTMLElement | null, point: { x: number; y: number
400414
if (!panel || !point) return false;
401415
const box = panel.getBoundingClientRect();
402416
if (box.width === 0 || box.height === 0) return false;
403-
const margin = Math.max(0, box.left);
404-
return point.x < box.right && point.y >= box.top - margin && point.y < box.bottom + margin;
417+
// The card's margin from the window's start edge: the left one, or the
418+
// right one in a right-to-left language (objectstack#37914).
419+
const rtl = isRightToLeft(panel);
420+
const margin = Math.max(0, rtl ? window.innerWidth - box.right : box.left);
421+
const onCardSide = rtl ? point.x >= box.left : point.x < box.right;
422+
return onCardSide && point.y >= box.top - margin && point.y < box.bottom + margin;
405423
}
406424

407425
/**

0 commit comments

Comments
 (0)