Skip to content

Commit 947e7b7

Browse files
authored
fix(DropdownMenu, ContextMenu): sheet chevrons follow the menu's own direction (#13774)
* fix(DropdownMenu, ContextMenu): sheet chevrons follow the menu's own direction * test(DropdownMenu): the RTL sheet case reads the computed flip, not the mirror classes
1 parent 4b3cf13 commit 947e7b7

7 files changed

Lines changed: 101 additions & 16 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] DropdownMenu, ContextMenu: in the touch sheet, a sub-menu row's chevron and the Back chevron now flip by the menu's own direction (its nearest `dir`), as the popover's already do. In a left-to-right menu inside a right-to-left page, the row chevron used to point left and the Back chevron right, against the sheet's own layout.
6+
7+
@cixzhang

‎docs/specs/components/DropdownMenu/DropdownMenu.spec.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ component-local concepts; each keeps its released default.
149149
| FR21 | Under a finger, in the touch modes (`presentation` not pinned to `'popover'`), the pointer menu MUST grow out of the Trigger button on the theme's entrance duration and easing tokens and collapse back into it on the theme's exit duration and easing (`spec:AST-094` FR7, FR31, FR45), and MUST close as a pan that starts outside it begins (FR32); a pinned `'popover'` keeps the layer's own entrance. A pan dismissal is the menu's own close: focus that was in the menu returns to the Trigger button, whose `aria-expanded` turns false. A finger's or a pen's open grows the menu, a tap's open at its lift included, and the grow follows the popover's path. A mouse and the keyboard keep the layer's own entrance and exit. Under Reduce Motion, where the primary pointer is coarse, the menu fades in at its size and fades out where it stands (`design:reduced-motion` DR2). Under a coarse primary pointer, taps stay held from the open until the menu is visible. Implementation gap: the menu has no pan-outside dismissal of its own. | `spec:AST-094` FR31, FR32; `family:overlay-dismissal` AV6 |
150150
| FR22 | Under a finger, in the touch modes, where the primary pointer is coarse (a phone or a tablet), a tap or a drag that lands while the pointer menu enters MUST reach nothing: it closes nothing, scrolls nothing, moves no focus and clicks nothing (`spec:AST-094` FR35). The finger that opened the menu still picks the row it lifts on (FR8). Keys and assistive technology stay live. A mouse, a pinned `'popover'` and a finger where the primary pointer is fine (a touchscreen laptop) hold nothing, as for `component:Drawer`. Implementation gap: after a finger, a still mouse's first press lands on the entering menu's shield unless the mouse rests where the page last heard it when the shield came up (`spec:AST-094` FR35). | `spec:AST-094` FR35; `architecture:layer-runtime` |
151151
| FR23 | Tab or Shift+Tab on a row at any level of a menu without `header` or `footer`, its own rows or an open sub-menu flyout's at any depth, closes every open level and the menu, calls `onOpenChange(false)` once, and leaves focus to move on from the trigger in page order (WAI-ARIA Menu Button). A level with a header or footer keeps FR15's and FR20's Tab cycle within it. | WAI-ARIA Menu Button pattern; current tests |
152+
| FR24 | A sub-menu row's chevron points the way its sub-menu opens, and a Back control's chevron points the way it returns, in the menu's own direction (its nearest `dir`), not the page's: in the pointer menu, its flyouts and drill-in views, and the touch sheet, in DropdownMenu and in ContextMenu (`docs/design/bidirectionality.md` DR6). | Bidirectionality guide DR6; current tests | |
152153

153154
### Allowed variation
154155

@@ -375,6 +376,7 @@ than adding a DropdownMenu-owned heading target.
375376
| FR21 | `DropdownMenuTouchGrow.test.tsx` (which opens grow); `DropdownMenuTouchGrow.interaction.browser.spec.ts` (Chromium, WebKit): the first tap after load, a tap in scrolling content and a held finger grow the menu out of its trigger, on the popover's path and timing. Evidence gap: pan dismissal, matching the FR21 gap | — | — | `audit:DropdownMenu/behavior` |
376377
| FR22 | `DropdownMenu.test.tsx` "DropdownMenu entrance under a finger" cases; `useMenuPress.test.tsx` "an input hold over the menu" cases; `DropdownMenuEntranceHold.interaction.browser.spec.ts` | A tap outside and a finger's slide while the menu enters; a mouse click | A tap during the entrance that closes the menu, clicks the page or moves focus, a slide that picks nothing, or a held mouse fails. | `audit:DropdownMenu/behavior` |
377378
| FR23 | `DropdownMenu.test.tsx` Tab cases; `DropdownMenuSubMenu.test.tsx` "Tab from a flyout leaves the whole menu" suite | top level, one and two levels down, Shift+Tab | A Tab that leaves any level open, a second `onOpenChange(false)`, or a prevented Tab fails. | `audit:DropdownMenu/accessibility` |
379+
| FR24 | `DropdownMenuSubMenu.test.tsx` direction cases (flyout and drill-in); `DropdownMenu.test.tsx` and `ContextMenu.test.tsx` "points the sheet … chevron by the menu direction, not the page" | an LTR menu in an RTL page and an RTL menu in an LTR page, flyout, drill-in and touch sheet | A chevron that flips by the page's direction instead of the menu's fails. | `audit:DropdownMenu/accessibility` |
378380
| PR1 | Evidence gap: no test asserts the listener and observer bounds | — | — | `audit:DropdownMenu/behavior` |
379381
| Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and targets | Missing, extra, prefixed, stale, or alias-backed mappings fail repository validation. | `audit:DropdownMenu/theming` |
380382

‎packages/core/src/ContextMenu/ContextMenu.test.tsx‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,42 @@ describe('ContextMenu', () => {
293293
expect(HTMLElement.prototype.showPopover).not.toHaveBeenCalled();
294294
});
295295

296+
it.each([
297+
{pageDir: 'rtl', menuDir: 'ltr', isFlipped: false},
298+
{pageDir: 'ltr', menuDir: 'rtl', isFlipped: true},
299+
] as const)(
300+
'points the sheet Back chevron by the menu direction, not the page (page $pageDir, menu $menuDir)',
301+
async ({pageDir, menuDir, isFlipped}) => {
302+
const user = userEvent.setup();
303+
render(
304+
<div dir={pageDir}>
305+
<div dir={menuDir}>
306+
<ContextMenu
307+
presentation="bottom-sheet"
308+
label="Row actions"
309+
items={[
310+
{label: 'Move to project', items: [{label: 'Apollo launch'}]},
311+
]}>
312+
<div>Right-click me</div>
313+
</ContextMenu>
314+
</div>
315+
</div>,
316+
);
317+
318+
fireEvent.contextMenu(screen.getByText('Right-click me'));
319+
await user.click(
320+
await screen.findByRole('button', {name: /Move to project/}),
321+
);
322+
const backIcon = screen
323+
.getByRole('button', {name: 'Back'})
324+
.querySelector('.astryx-icon');
325+
expect(backIcon).not.toBeNull();
326+
expect(
327+
getComputedStyle(backIcon as Element).transform === 'scaleX(-1)',
328+
).toBe(isFlipped);
329+
},
330+
);
331+
296332
it('names the sheet after a node-label submenu while its level shows', async () => {
297333
const user = userEvent.setup();
298334

‎packages/core/src/ContextMenu/ContextMenu.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ import {
9696
easeVars,
9797
shadowVars,
9898
} from '../theme/tokens.stylex';
99-
import {mergeProps, rtlStyles} from '../utils';
99+
import {mergeProps} from '../utils';
100+
import {menuDirectionMirror} from '../DropdownMenu/menuDirectionMirror.stylex';
100101
import type {BaseProps} from '../BaseProps';
101102
import type {StyleXStyles} from '../theme/types';
102103
import {themeProps} from '../utils/themeProps';
@@ -907,7 +908,11 @@ export function ContextMenu({
907908
variant="ghost"
908909
size="sm"
909910
icon={
910-
<Icon icon="chevronLeft" size="sm" xstyle={rtlStyles.mirror} />
911+
<Icon
912+
icon="chevronLeft"
913+
size="sm"
914+
xstyle={menuDirectionMirror.mirror}
915+
/>
911916
}
912917
isIconOnly
913918
onClick={() => {

‎packages/core/src/DropdownMenu/DropdownMenu.test.tsx‎

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {warmMenuBottomSheet} from './__tests__/warmMenuBottomSheet';
3333
import {DropdownMenuSubMenu} from './DropdownMenuSubMenu';
3434
import {Divider} from '../Divider';
3535
import {Tooltip} from '../Tooltip/Tooltip';
36-
import {rtlStyles} from '../utils';
3736
import {__resetInteractionModalityForTest} from '../utils/interactionModality';
3837
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
3938
import {spacingVars} from '../theme/tokens.stylex';
@@ -411,6 +410,46 @@ describe('DropdownMenu', () => {
411410
).toBeInTheDocument();
412411
});
413412

413+
it.each([
414+
{pageDir: 'rtl', menuDir: 'ltr', isFlipped: false},
415+
{pageDir: 'ltr', menuDir: 'rtl', isFlipped: true},
416+
] as const)(
417+
'points the sheet chevrons by the menu direction, not the page (page $pageDir, menu $menuDir)',
418+
async ({pageDir, menuDir, isFlipped}) => {
419+
const user = userEvent.setup();
420+
render(
421+
<div dir={pageDir}>
422+
<div dir={menuDir}>
423+
<DropdownMenu
424+
button={{label: 'Project actions'}}
425+
presentation="bottom-sheet"
426+
items={[
427+
{label: 'Move to project', items: [{label: 'Apollo launch'}]},
428+
]}
429+
/>
430+
</div>
431+
</div>,
432+
);
433+
434+
await user.click(screen.getByRole('button', {name: /Project actions/}));
435+
const row = screen.getByRole('button', {name: /Move to project/});
436+
const rowChevron = row
437+
.closest('li')
438+
?.querySelector<HTMLElement>('.astryx-icon:last-of-type');
439+
expect(rowChevron).not.toBeNull();
440+
const flipped = (element: Element) =>
441+
getComputedStyle(element).transform === 'scaleX(-1)';
442+
expect(flipped(rowChevron as HTMLElement)).toBe(isFlipped);
443+
444+
await user.click(row);
445+
const backIcon = screen
446+
.getByRole('button', {name: 'Back'})
447+
.querySelector('.astryx-icon');
448+
expect(backIcon).not.toBeNull();
449+
expect(flipped(backIcon as Element)).toBe(isFlipped);
450+
},
451+
);
452+
414453
it('names the sheet after the node-label submenu that opened, also across sections', async () => {
415454
const user = userEvent.setup();
416455

@@ -546,9 +585,8 @@ describe('DropdownMenu', () => {
546585

547586
it('mirrors bottom-sheet drill-in affordances under RTL', async () => {
548587
const user = userEvent.setup();
549-
const {className: mirrorClassName} = stylex.props(rtlStyles.mirror);
550-
const mirrorClasses = mirrorClassName?.split(' ') ?? [];
551-
expect(mirrorClasses.length).toBeGreaterThan(0);
588+
const flipped = (element: Element) =>
589+
getComputedStyle(element).transform === 'scaleX(-1)';
552590

553591
render(
554592
<div dir="rtl">
@@ -573,17 +611,13 @@ describe('DropdownMenu', () => {
573611
.closest('li')
574612
?.querySelector('.astryx-icon');
575613
expect(forwardIcon).not.toBeNull();
576-
for (const className of mirrorClasses) {
577-
expect(forwardIcon).toHaveClass(className);
578-
}
614+
expect(flipped(forwardIcon as Element)).toBe(true);
579615

580616
await user.click(submenuButton);
581617
const backButton = screen.getByRole('button', {name: 'Back'});
582618
const backIcon = backButton.querySelector('.astryx-icon');
583619
expect(backIcon).not.toBeNull();
584-
for (const className of mirrorClasses) {
585-
expect(backIcon).toHaveClass(className);
586-
}
620+
expect(flipped(backIcon as Element)).toBe(true);
587621
});
588622

589623
it('uses the BottomSheet for adaptive presentation on compact touch', async () => {

‎packages/core/src/DropdownMenu/DropdownMenu.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ import {
117117
durationVars,
118118
easeVars,
119119
} from '../theme/tokens.stylex';
120-
import {isRenderable, mergeProps, rtlStyles} from '../utils';
120+
import {isRenderable, mergeProps} from '../utils';
121+
import {menuDirectionMirror} from './menuDirectionMirror.stylex';
121122
import type {BaseProps} from '../BaseProps';
122123
import {themeProps} from '../utils/themeProps';
123124
import {
@@ -890,7 +891,7 @@ function DropdownMenuBottomSheet({
890891
<Icon
891892
icon="chevronLeft"
892893
size="sm"
893-
xstyle={rtlStyles.mirror}
894+
xstyle={menuDirectionMirror.mirror}
894895
/>
895896
}
896897
isIconOnly

‎packages/core/src/DropdownMenu/MenuBottomSheetActionList.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {pressBelongsToControl} from '../hooks/useClickableContainer';
2020
import {elementAtMenuPoint, useMenuPressInternal} from '../hooks/useMenuPress';
2121
import {useMergedRefs} from '../hooks/useMergedRefs';
2222
import {colorVars, spacingVars} from '../theme/tokens.stylex';
23-
import {rtlStyles} from '../utils/rtlStyles';
23+
import {menuDirectionMirror} from './menuDirectionMirror.stylex';
2424
import {useInteractionModalityTracking} from '../utils/interactionModality';
2525
import type {DropdownMenuItemData, DropdownMenuOption} from './DropdownMenu';
2626
import {isModifiedClick} from './menuItemRoles';
@@ -217,7 +217,7 @@ export function MenuBottomSheetActionList({
217217
icon="chevronRight"
218218
size="sm"
219219
color="secondary"
220-
xstyle={rtlStyles.mirror}
220+
xstyle={menuDirectionMirror.mirror}
221221
/>
222222
) : (
223223
item.endContent

0 commit comments

Comments
 (0)