Skip to content

fix(mobile-nav): resolve auto side before opening - #11282

Closed
bezabyte wants to merge 6 commits into
meta:mainfrom
bezabyte:fix/issue-11206-mobile-nav-rtl
Closed

bezabyte wants to merge 6 commits into
meta:mainfrom
bezabyte:fix/issue-11206-mobile-nav-rtl

Conversation

@bezabyte

@bezabyte bezabyte commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Primary intent

Fix #11206 by making MobileNav resolve an auto side before its first modal open and by respecting RTL inline direction.

User or maintainer impact

On a fresh load, an RTL MobileNav using side="auto" could start its first slide from the wrong edge because showModal() ran before the trigger-position measurement completed. Later opens reused the resolved state, which made the bug look intermittent.

Change

  • Resolve the auto side in a layout effect before the open/close effect can call showModal().
  • Keep the native dialog mounted and displayed while that side is being resolved; only the drawer panel is temporarily withheld from its open presentation. This preserves the native dialog node, focus restoration, delayed close, and any state held by the navigation content.
  • Reset the resolved-auto state only after the native dialog actually closes, including unmount teardown, so reopening during the delayed close remains a real entrance.
  • Hold pointer input for a reopened entrance as well as the first entrance; keyboard and assistive-technology access remain live.
  • Map the trigger's physical position to logical inline-start/inline-end with the shared isRtlElement() helper.
  • Add a four-case LTR/RTL and left/right unit matrix, plus regressions for mid-close reopen, content-state preservation, and unmount cleanup.
  • Keep the Chromium proof for the actual first-frame entrance transform and add a patch changeset for @astryxdesign/core.

Evidence

Direction Trigger Result
LTR left half opens from logical start
LTR right half opens from logical end
RTL left half opens from logical end
RTL right half opens from logical start

The browser proof reads the drawer's computed transform during the entrance, so it checks the physical origin rather than only the final data-side attribute. A static screenshot would not establish which transform was used on the first frame.

Scope

Components: MobileNav auto-side resolution and first/reopened entrance presentation

No other issue from the surrounding mobile navigation area is claimed here.

Testing

  • pnpm exec vitest run --project ui packages/core/src/MobileNav/MobileNav.test.tsx packages/core/src/MobileNav/MobileNavReopen.test.tsx packages/core/src/MobileNav/MobileNavTouchPresentation.test.tsx packages/core/src/MobileNav/MobileNavRootScrollClaim.test.tsx — 41 passed.
  • pnpm -F @astryxdesign/core typecheck — passed.
  • pnpm exec eslint packages/core/src/MobileNav/MobileNav.tsx packages/core/src/MobileNav/MobileNavTouchPresentation.test.tsx — passed.
  • pnpm storybook:build — completed successfully.
  • pnpm exec playwright test packages/core/src/MobileNav/__tests__/MobileNavAutoSide.a11y.chromium.spec.ts --config playwright.config.ts --project chromium — 4 passed.
  • Full repository pre-commit checks — passed.

Closes #11206.

@vercel

vercel Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 12, 2026 6:46pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 11, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Nov 11, 2026
@astracat-bot

astracat-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟡 Reviewed (for maintainers only) Nov 13, 2026, 3:36 PM UTC

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking this down: the auto side now follows the trigger in right-to-left layouts, and the reported first open (RTL, toggle in the left half) slides in correctly. A few changes are needed before this can merge:

  • The first open still slides in from the wrong edge whenever side="auto" resolves to start: the dialog is already rendered with the old end classes when the layout effect measures the trigger (MobileNav.tsx:577), so in Chromium an RTL toggle in the right half sweeps the drawer in from the left edge, and an LTR toggle in the left half slides it leftward from inside the viewport.
  • The direction check at MobileNav.tsx:579-583 re-implements isRtlElement (packages/core/src/hooks/isRtlElement.ts), and its closest('[dir="rtl"]') and <html dir> fallbacks override the trigger's computed direction, so a toggle inside a dir="ltr" region of an RTL page opens the drawer on the far side; please call isRtlElement(trigger) and set direction on the trigger in the test instead.
  • The changeset says the auto side now resolves before the first open, but the test checks only data-side at showModal(), and its LTR case (a right-half trigger expecting end) already passes on main; once the first point is fixed, make that case a left-half trigger expecting start and add a browser check of where the entrance starts.

If the drawer stays unrendered on an opening until its side is resolved, its first computed style already carries that side, which should settle the first and third points together. CI has not run on this head yet; a maintainer needs to add the ci:run label.

Automated review (maintainer link)

@bezabyte

Copy link
Copy Markdown
Contributor Author

Addressed the requested MobileNav changes in 6fc4b6273: auto-side dialogs stay unmounted through every unresolved open commit, RTL detection now uses isRtlElement(trigger), and the matrix covers LTR/RTL openers on both viewport halves. Added MobileNavAutoSide.a11y.chromium.spec.ts; the built Storybook regression passes all four Chromium cases and the unit suite passes 25/25. The first-frame check verifies the physical entrance origin, not only the final data-side.

@bezabyte

Copy link
Copy Markdown
Contributor Author

I checked the requested changes against the current head 6fc4b6273.

The follow-up now:

  • keeps an auto-side dialog unmounted until its side is resolved, so the first rendered frame has the correct entrance class;
  • uses the shared isRtlElement(trigger) helper;
  • sets the trigger's own direction in the unit matrix;
  • covers LTR and RTL openers on both sides of the viewport;
  • checks the opening transform in real Chromium, not only the final data-side.

Local verification:

  • MobileNav.test.tsx: 25 passed
  • MobileNavAutoSide.a11y.chromium.spec.ts: 4 passed

The remaining ci:run label is maintainer-only; the fork account cannot add it.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick follow-up: the shared isRtlElement check, the four-case matrix and the Chromium entrance test address the earlier review, and keeping the drawer out of the measuring commit fixes the first slide. One part of the new approach needs to change before this can merge:

  • Rendering null while the side resolves (MobileNav.tsx:719-721) replaces the <dialog> on every default-side open, so the unmount-only effect (MobileNav.tsx:659-668) checks a stale or missing node, and an open drawer that unmounts is no longer closed and no longer returns focus to its opener; by this code path the existing closes the dialog when unmounted while fully open test leaves the dialog open.
  • A reopen before the delayed close fires removes the still-open dialog, so the replacement records the page body as its opener (MobileNav.tsx:605-611) and the next close leaves focus on the body instead of the toggle.
  • Every default-side open remounts the drawer's content, so an expanded or collapsed SideNav group and any typed text reset between opens, which they do not on main.
  • The Testing section reports results from the earlier commit (two cases for the new test, which now has four, and a run that includes the unmount test above), so please rerun at the final head and update it.

Keeping the dialog mounted and withholding only its open styling (styles.open) on an opening whose side is still unresolved keeps the correct first slide without replacing the node; default-side tests for an unmount while open, a reopen mid-close and content state across a reopen would pin it. CI has not run on this head yet; a maintainer needs to add the ci:run label.

Claims and files checked
  • Changeset, the auto side is resolved before the first open: verified (MobileNav.tsx:567-592, :602, :719-721).
  • Changeset, the auto side respects RTL inline direction: verified (MobileNav.tsx:580-584).
  • Description, the side resolves in a layout effect before showModal() can run: verified (MobileNav.tsx:567, :602).
  • Description, the modal waits for the auto-side resolution: verified, and it applies to every auto open (MobileNav.tsx:568-571, :719-721).
  • Description, the physical position maps to logical start or end by direction: verified; the code uses the opener's computed direction (MobileNav.tsx:580).
  • Description, a regression test records the side at showModal() for LTR and RTL: verified (MobileNav.test.tsx:334-407, four cases).
  • Description, a patch changeset is added: verified.
  • Description, on the base the first open could use the stale side: verified from the base source.
  • Description, the existing entry-animation tests cover both edges: present (MobileNavEntryAnimation.test.tsx:189-203); not run here.
  • Description, the new test passed with two cases: false at this head, which has four cases.
  • Description, 48 tests passed across three files including the close edge cases: false at this head by code path (MobileNavCloseEdgeCases.test.tsx:175).
  • Description, typecheck, lint, changeset and pre-commit checks passed: not verified; could not be run here.
  • Author comment, auto-side dialogs stay unmounted through every unresolved open commit: verified (MobileNav.tsx:719-721).
  • Author comment, 25 unit tests and four Chromium cases passed: not verified; could not be run here.
  • .changeset/mobile-nav-auto-side-before-open.md: clear.
  • packages/core/src/MobileNav/MobileNav.tsx: findings 1-3.
  • packages/core/src/MobileNav/MobileNav.test.tsx: clear for what it covers; no default-side case for the unmount, reopen or content-state paths.
  • packages/core/src/MobileNav/__tests__/MobileNavAutoSide.a11y.chromium.spec.ts: clear; it checks the entrance origin only.

Automated review (maintainer link)

@bezabyte
bezabyte force-pushed the fix/issue-11206-mobile-nav-rtl branch from 6fc4b62 to 7af5542 Compare November 12, 2026 05:01
@bezabyte

Copy link
Copy Markdown
Contributor Author

Addressed the latest review on 7af5542.

The auto-side opening path now keeps the existing dialog mounted. While the trigger is being measured, it withholds only the dialog open styling; once the layout effect resolves the side, the normal open effect shows the same node. That keeps unmount cleanup, focus restoration, the delayed close, mid-close reopen, and stateful navigation content on one dialog instance.

The direction branch now uses the shared isRtlElement(trigger) helper. I also added coverage for:

  • the four LTR/RTL x left/right opener cases;
  • reopening before the delayed close completes without remounting the dialog;
  • preserving stateful navigation content across that reopen;
  • closing the native dialog when an open MobileNav unmounts;
  • the real Chromium entrance transform in all four direction/position cases.

Verification:

  • MobileNav UI suites: 36 passed
  • pnpm -F @astryxdesign/core typecheck: passed
  • Storybook build: completed successfully
  • Chromium auto-side proof: 4 passed
  • repository pre-commit checks: passed

The PR body is updated to match the final implementation and test results.

cixzhang added a commit to mahmed74/astryx that referenced this pull request Nov 12, 2026
A drawer open in the server markup resolves its edge after hydration. By
then showModal() may have moved focus into the drawer, so the lookup measured
the drawer panel instead of the opener and skipped the aria-controls fallback.
Focus inside the dialog now counts as no focus. The SSR test starts from focus
on the drawer panel, measured away from the opener, and asserts the edge still
follows the opener through its aria-controls.

The Chromium entrance-edge spec (LTR and RTL, opener in either half) is
adopted from meta#11282, scoped to MobileNav paths.

Co-authored-by: mahmed74 <[email protected]>
Co-authored-by: Josh <[email protected]>
cixzhang added a commit to mahmed74/astryx that referenced this pull request Nov 12, 2026
The spec checks in real Chromium that the drawer enters from the edge beside
its opener, in LTR and RTL, with the opener in either half of the viewport.
A branch merge had dropped it; it returns unchanged, from meta#11282.

Co-authored-by: Josh <[email protected]>
Co-authored-by: mahmed74 <[email protected]>

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick turnaround. Keeping the dialog mounted fixes the three problems from the last review, and the shared isRtlElement check, the four-case matrix and the Chromium entrance test cover what the earlier reviews asked for. One change is still needed before this can merge:

  • Withholding styles.open while the side resolves (MobileNav.tsx:732) leaves AppShell's drawer, which always uses the default side, at display: none in the commit that opens it; AppShell's spec requires an open to be visible in the commit that carries it, and the existing test shows a controlled open in the same commit, not one effect later (MobileNavCloseEdgeCases.test.tsx:628) fails on this path.

That gate was the last review's own suggestion, and it missed this requirement. Keeping the dialog displayed and holding only the drawer panel (display: none on the panel until the side resolves) keeps the correct first slide, as long as a reopen during a pending close skips the hold. CI has not run on this head yet; a maintainer needs to add the ci:run label.

Claims and files checked
  • Changeset, the auto side is resolved before the first open: verified (MobileNav.tsx:567-592, :602, :732).
  • Changeset, the auto side respects RTL inline direction: verified (MobileNav.tsx:580-584).
  • Description, on main the first slide could start from the wrong edge because the measured side rendered after showModal(): verified from main's source.
  • Description, later opens reused the resolved side: verified (the side state persists between opens).
  • Description, the side resolves in a layout effect before the open effect can call showModal(): verified (MobileNav.tsx:567, :602).
  • Description, the dialog stays mounted and only its open styling is withheld: verified (MobileNav.tsx:715, :732); this is what hides AppShell's drawer for one commit.
  • Description, the dialog node, focus return, delayed close and content state are preserved: verified by code path (MobileNav.tsx:605-613, :659-668) and the new tests (MobileNavTouchPresentation.test.tsx:265-305); no default-side focus test.
  • Description, the shared isRtlElement helper maps position to logical start or end: verified (MobileNav.tsx:87, :580).
  • Description, a four-case matrix plus reopen, content-state and unmount tests: verified present (MobileNav.test.tsx:334-407, MobileNavTouchPresentation.test.tsx:265-305).
  • Description, a Chromium test reads the entrance transform in four cases: verified present; not run.
  • Description, a patch changeset is added: verified.
  • Description, 36 tests passed across three files: the count matches (25, 10 and 1); not run; the run leaves out MobileNavCloseEdgeCases.test.tsx, whose same-commit test fails on this path.
  • Description, typecheck, lint, Storybook build, the four Chromium cases and pre-commit checks passed: not verified.
  • .changeset/mobile-nav-auto-side-before-open.md: clear.
  • packages/core/src/MobileNav/MobileNav.tsx: the finding above.
  • packages/core/src/MobileNav/MobileNav.test.tsx: clear.
  • packages/core/src/MobileNav/MobileNavTouchPresentation.test.tsx: clear.
  • packages/core/src/MobileNav/__tests__/MobileNavAutoSide.a11y.chromium.spec.ts: clear; it covers focused openers only.

Automated review (maintainer link)

@bezabyte
bezabyte force-pushed the fix/issue-11206-mobile-nav-rtl branch from 7af5542 to e5a035c Compare November 12, 2026 16:18
@bezabyte

Copy link
Copy Markdown
Contributor Author

Addressed the final visibility review in e5a035c.

  • The dialog keeps styles.open in the opening commit, so AppShell sees the open drawer immediately.
  • Only the drawer panel gets display: none while side="auto" is unresolved; it becomes visible after the layout measurement supplies the logical side.
  • A reopen during a pending close keeps the existing dialog and skips a second entrance input hold.

Verification: MobileNav close-edge, touch-presentation, entry-animation, reopen, MobileNav, and AppShell suites pass (65 targeted tests); repository pre-commit checks pass. The Chromium entrance cases and ci:run label still require maintainer CI.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: the right-to-left mapping and the first-open slide now follow MobileNav's spec, and the earlier remount, focus-return and same-commit visibility problems are fixed, but three small fixes remain.

  • The drawer panel's pending state reads dialogRef.current?.open during render (MobileNav.tsx:722-723), but rendered output has to come from props, state and context, so reset autoSideResolved where the dialog actually closes (the close timer and the unmount teardown) instead of on every close, and drop the read.
  • A reopen during a pending close now slides the drawer back in with no touch input hold (MobileNav.tsx:620-626), so a tap on the backdrop during that slide closes it again; take the entrance hold after the if (!dialog.open) block, as before.
  • The description says the dialog's open styling is withheld while the side resolves, but the dialog now stays displayed and only the drawer panel is hidden, so please update that line.

The three new setAutoSideResolved calls also need lint reasons, because CI runs that lint rule as an error. CI has not run on this head yet; it waits for a maintainer. #11227 changes the same lines for the same issue, so whichever lands second will need a rebase.

Claims and files checked
  • Claim: the auto side resolves in a layout effect before showModal() runs: verified (MobileNav.tsx:574-609).
  • Claim: the dialog stays mounted while the side resolves: verified (the dialog always renders).
  • Claim: only the dialog's open styling is withheld while the side resolves: false (the dialog keeps it at MobileNav.tsx:740; the drawer panel is hidden at :767).
  • Claim: the opener's position maps to logical start or end with the shared right-to-left helper: verified (MobileNav.tsx:587-591).
  • Claim: a four-case direction and position unit matrix, plus tests for a mid-close reopen, content state and unmount cleanup: verified (MobileNav.test.tsx:334-407, MobileNavTouchPresentation.test.tsx:265-301).
  • Claim: a Chromium test reads the drawer's computed transform during the entrance: verified (MobileNavAutoSide.a11y.chromium.spec.ts:421-428).
  • Claim: the evidence table's four direction and position results: verified against MobileNav.tsx:590.
  • Claim: the first open could slide from the wrong edge because showModal() ran before the measurement, and later opens reused the side: verified against the base code.
  • Claim: the listed test, typecheck, lint, Storybook and browser runs passed: not checked; these are the author's own runs.
  • Changeset: an auto side resolves before the first open and follows right-to-left direction: verified (MobileNav.tsx:574-609, :587-591).
  • .changeset/mobile-nav-auto-side-before-open.md: clear.
  • packages/core/src/MobileNav/MobileNav.tsx: the findings above.
  • packages/core/src/MobileNav/MobileNav.test.tsx: clear.
  • packages/core/src/MobileNav/MobileNavTouchPresentation.test.tsx: clear; no test asserts a held reopen.
  • packages/core/src/MobileNav/__tests__/MobileNavAutoSide.a11y.chromium.spec.ts: clear.

Automated review (maintainer link)

@bezabyte

Copy link
Copy Markdown
Contributor Author

Addressed the latest review findings in bba8f76bf:

  • Removed the render-time dialogRef.current?.open read; pending presentation now derives from React state.
  • Reset autoSideResolved only after the native dialog closes, including unmount teardown, so a pending close cannot leave the next open in a stale resolved state.
  • Restored the entrance input hold for reopen-during-close, and added an assertion for that behavior.
  • Added the required lint reasons for the effect state updates.
  • Clarified the PR description: the dialog remains displayed while only the drawer panel's open presentation is withheld.

Verification: 4 focused files, 41 tests passed; repository pre-commit checks passed.

The engineering-owner/spec approval request remains unchanged; this update resolves the implementation findings.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: the right-to-left mapping, the first-open slide and the reopen touch hold now follow MobileNav's spec, and the earlier render-time read, lint and description issues are fixed, but one small fix remains.

  • The close timer and the unmount teardown now reset autoSideResolved for every side (MobileNav.tsx:632, :674), so a side="start" or "end" drawer reopened after a close waits for the layout effect's measurement-free setAutoSideResolved(true) (:595-596) before showModal() runs, which keeps a value render can derive in Effect-set state; derive const isSideResolved = side !== 'auto' || autoSideResolved;, gate the open effect on it, and drop that fixed-branch call.

The four-case Chromium entrance test is a useful guard for the first-slide fix. CI has not run on this head yet; it waits for a maintainer. #11227 changes the same lines for the same issue, so whichever lands second will need a rebase.

Claims and files checked
  • Claim: the auto side resolves in a layout effect before showModal() runs: verified (MobileNav.tsx:574-608).
  • Claim: the dialog stays mounted and displayed while only the drawer panel waits: verified (MobileNav.tsx:741, :768).
  • Claim: the dialog node, focus restoration, delayed close and content state are preserved: verified (MobileNavTouchPresentation.test.tsx:266-302).
  • Claim: the flag resets only after the dialog actually closes, including unmount teardown: verified (MobileNav.tsx:632, :674); it resets for every side, which is the finding above.
  • Claim: a reopened entrance holds pointer input while keys and assistive technology stay live: verified (MobileNav.tsx:620-625, MobileNavTouchPresentation.test.tsx:255).
  • Claim: the opener's position maps to logical start or end with the shared right-to-left helper: verified (MobileNav.tsx:584-587).
  • Claim: a four-case direction and position matrix, plus reopen, content-state and unmount tests: verified (MobileNav.test.tsx:334-407, MobileNavTouchPresentation.test.tsx:242-302).
  • Claim: a Chromium test reads the drawer's computed transform during the entrance: verified (MobileNavAutoSide.a11y.chromium.spec.ts:77-88).
  • Claim: the evidence table's four direction and position results: verified against MobileNav.tsx:587.
  • Claim: the first open slid from the wrong edge because showModal() ran before the measurement, and later opens reused the side: verified against the base code.
  • Claim: the listed test, typecheck, lint, Storybook and browser runs passed: not checked; these are the author's own runs.
  • Changeset: an auto side resolves before the first open and follows right-to-left direction: verified (MobileNav.tsx:574-598, :584-587).
  • .changeset/mobile-nav-auto-side-before-open.md: clear.
  • packages/core/src/MobileNav/MobileNav.tsx: the finding above; one comment-style suggestion inline.
  • packages/core/src/MobileNav/MobileNav.test.tsx: clear.
  • packages/core/src/MobileNav/MobileNavTouchPresentation.test.tsx: clear.
  • packages/core/src/MobileNav/__tests__/MobileNavAutoSide.a11y.chromium.spec.ts: clear.

Automated review (maintainer link)

Comment on lines +194 to +197
// The dialog stays visible as soon as an open is committed. On the first
// `side="auto"` render the panel waits one layout pass for its edge to be
// measured, so AppShell does not inherit a hidden dialog while the drawer
// is still resolving its placement.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking (comment style): the panel waits on every auto open that follows a completed close, not only the first, and the second sentence runs 33 words. Suggested:

// The panel stays hidden until the auto side is measured, so the entrance
// starts from the measured edge. The dialog stays displayed, so AppShell
// shows the open in the commit that carries it.

@bezabyte

Copy link
Copy Markdown
Contributor Author

Addressed the latest review in c2d7ab2c0.

  • The open/close effect now gates on isSideResolved = side !== 'auto' || autoSideResolved.
  • Fixed start/end sides no longer wait for the auto-side state after a close.
  • Auto-side still resets on close/unmount and resolves from the trigger before reopening.

Verification: MobileNav-focused suite 54/54 passed; targeted ESLint and Prettier passed; repository pre-commit checks passed.

The remaining ci:run label and engineering-owner/spec gate are maintainer actions.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: the right-to-left mapping and the first-open slide now work in a real right-to-left layout (checked in Chromium), and the fixed-side reopen from the last review is fixed, but two small fixes remain.

  • Switching side from "start" or "end" to "auto" while a close is pending now restarts the close delay, because isSideResolved (MobileNav.tsx:566) sits in the open/close effect's dependencies (:650) and is false for a fixed side after its first completed close; gating the effect on isOpen && side === 'auto' && !autoSideResolved instead keeps the close within 250 ms and keeps every existing MobileNav and AppShell test passing.
  • Miss: the Chromium spec's right-to-left cases set dir on #storybook-root (MobileNavAutoSide.a11y.chromium.spec.ts:55-56), but Storybook's decorator keeps the story wrapper at dir="ltr", so the dialog stays left-to-right and those cases pass only on the mirrored transform; opening the story with &globals=direction:rtl and dropping the root dir and the opener's inline direction renders a real right-to-left dialog, and all four cases pass that way.

The first point comes from the derivation the last review suggested, which missed this case; holding the side the opening render saw (usePresentationHold({isOpen, presentation: side}), with the flag starting at false) also covers a fixed-to-auto switch while open or before the first open. CI has not run on this head yet; it waits for a maintainer. #11227 changes the same lines for the same issue, so whichever lands second will need a rebase.

Claims and files checked
  • Claim: the auto side resolves in a layout effect before showModal(): verified (MobileNav.tsx:575-607; the direction matrix passes, and fails on the base in three of four cases).
  • Claim: the dialog stays mounted and displayed while only the drawer panel waits: verified (:740, :767; the AppShell same-commit test passes).
  • Claim: the dialog node, focus restoration, delayed close and content state are preserved: verified (MobileNavTouchPresentation.test.tsx:266-302), except the delayed close on a fixed-to-auto switch (first point above).
  • Claim: the flag resets only after the dialog closes, including unmount teardown: verified (MobileNav.tsx:631, :673).
  • Claim: a reopened entrance holds pointer input while keys and assistive technology stay live: verified (:619-624, MobileNavTouchPresentation.test.tsx:255).
  • Claim: the opener's position maps to logical start or end with the shared right-to-left helper: verified (MobileNav.tsx:585-589).
  • Claim: a four-case direction matrix plus reopen, content-state and unmount tests: verified (run, all passing).
  • Claim: the Chromium test checks the physical entrance origin: true for its left-to-right cases, false for its right-to-left cases (second point above).
  • Claim: the evidence table's four direction and position results: verified in a right-to-left Storybook layout in Chromium.
  • Claim: the listed unit, typecheck, lint, Storybook build and browser runs pass: reproduced; the pre-commit run was not repeated.
  • Claim: fixed start/end sides no longer wait for the auto-side state after a close: verified (MobileNavCloseEdgeCases.test.tsx:226).
  • Changeset: an auto side resolves before the first open and follows right-to-left direction: verified for a focused opener.
  • .changeset/mobile-nav-auto-side-before-open.md: clear.
  • packages/core/src/MobileNav/MobileNav.tsx: first point above; two comment-style notes.
  • packages/core/src/MobileNav/MobileNav.test.tsx: clear.
  • packages/core/src/MobileNav/MobileNavCloseEdgeCases.test.tsx: clear; the new reopen test also passes on the previous head.
  • packages/core/src/MobileNav/MobileNavTouchPresentation.test.tsx: clear.
  • packages/core/src/MobileNav/__tests__/MobileNavAutoSide.a11y.chromium.spec.ts: second point above.

Automated review (maintainer link)

releaseHoldRef.current = null;
};
}, [isOpen, releasePresentation]);
}, [isOpen, isSideResolved, releasePresentation]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isSideResolved brings side into this effect's dependencies. A fixed-side drawer's first completed close sets autoSideResolved to false (line 631), and nothing sets it back for a fixed side, so a later switch from "start" or "end" to "auto" during a pending close flips this value: the cleanup clears the close timer and the close branch arms a fresh full delay. In a unit test the dialog is still open 300 ms after the request, past MobileNav FR5's 250 ms, where the base and the previous head have closed it. The comment above the layout effect and the "does not restart the pending close when the side prop changes" test guard exactly this.

Gating on a value that is false whenever isOpen is false keeps side out of a pending close:

const isAutoSidePending = isOpen && side === 'auto' && !autoSideResolved;
// ...
if (isOpen && !isAutoSidePending) {
// ...
}, [isAutoSidePending, isOpen, releasePresentation]);

With that edit the MobileNav and AppShell suites still pass. This corrects the derivation the last review suggested, which missed the fixed-to-auto case.

Comment on lines +55 to +58
const root = document.getElementById('storybook-root');
root?.setAttribute('dir', nextDirection);
Object.assign(element.style, {
direction: nextDirection,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storybook's decorator wraps every story in <div dir={direction}>, ltr unless the direction global is rtl, so dir on #storybook-root does not reach the dialog: its computed direction stays ltr in both "rtl" cases. They pass only because the drawer's transform uses :is([dir="rtl"] *), which matches the root, while its inset follows the wrapper; at 80 px the drawer rests on the right edge and starts mid-screen (x 364, translateX −316).

Opening the story in a real right-to-left layout fixes it, and all four cases pass that way:

await page.goto(
  `${storybook.origin}/iframe.html?id=core-mobilenav--default&viewMode=story${direction === 'rtl' ? '&globals=direction:rtl' : ''}`,
);

Then drop the root dir write and the opener's inline direction, and assert getComputedStyle(dialog).direction so the setup cannot drift again.

cixzhang added a commit that referenced this pull request Nov 13, 2026
…rst open (#11227)

* fix(MobileNav): side="auto" opens from the opener's inline edge in RTL and on first open

With side="auto", the drawer edge came from the focused element's physical
position, so in RTL an opener at the inline start resolved to the far side.
When nothing was focused (a touch tap does not focus a button in every
mobile browser), the first open kept the default "end", which is the left
edge in RTL; later opens worked because focus had returned to the toggle.

Resolve the side relative to the text direction, and fall back to the
element that controls the drawer (via aria-controls) when nothing is
focused.

Fixes #11206

* fix(MobileNav): resolve side="auto" before the first open frame

Address review feedback on #11227.

- Resolve the auto side while rendering the closed-to-open transition
  instead of in an Effect, so the first open frame already has the right
  edge rather than rendering on `end` and jumping.
- Match the unfocused fallback's `aria-controls` tokens against the
  dialog's rendered id (`dialogId`, `dialogRef.current.id`, or a caller
  `id`), so a standalone MobileNav with its own id resolves correctly.
- Read direction through `isRtlElement` instead of re-implementing it.
- Shorten the focus-fallback comment.
- Add tests for a caller-supplied id and for the side being set in the
  commit that opens the drawer.

* fix(MobileNav): resolve side="auto" after hydration, not during it

An already-open side="auto" drawer ran the render-time opener lookup in
the hydrating render, reading focus and layout the server never saw. That
could pick a different side than the server markup and cause a hydration
mismatch.

- Gate the closed-to-open side resolution on a useSyncExternalStore flag
  (false on the server and while hydrating, true after), as Timestamp
  does. A drawer open at hydration keeps the server's default edge for
  that render and resolves from the opener in the next one.
- Suppress @eslint-react/purity on the aria-controls lookup with a
  justification: it now runs only on the closed-to-open render, never on
  the server or while hydrating, and an Effect would commit the default
  edge first.
- Add MobileNavAutoSideSsr.test.tsx: server-render then hydrate in RTL
  with no hydration error, and the opener-resolved side afterwards.
- Use (string | null | undefined)[] in MobileNavAutoSideRtl.test.tsx
  (@typescript-eslint/array-type).
- Tighten the opener-lookup comment.

* Merge main into fix/rtl-mobile-sidenav-first-open; use the shared hydration hook

MobileNav reads the hydrating render through Core's useIsHydrating instead
of its own useSyncExternalStore copy, and two comments are shorter.

Co-authored-by: mahmed74 <[email protected]>

* feedback

* fix(MobileNav): focus inside the drawer is not the side="auto" opener

A drawer open in the server markup resolves its edge after hydration. By
then showModal() may have moved focus into the drawer, so the lookup measured
the drawer panel instead of the opener and skipped the aria-controls fallback.
Focus inside the dialog now counts as no focus. The SSR test starts from focus
on the drawer panel, measured away from the opener, and asserts the edge still
follows the opener through its aria-controls.

The Chromium entrance-edge spec (LTR and RTL, opener in either half) is
adopted from #11282, scoped to MobileNav paths.

Co-authored-by: mahmed74 <[email protected]>
Co-authored-by: Josh <[email protected]>

* fix(MobileNav): resolve side="auto" from the opener when a server-open drawer hydrates

For a drawer open in the server markup, showModal() moves focus into the
dialog before the post-hydration render resolves the edge. The drawer
itself was then taken as the opener, so the side was measured from the
drawer instead of the toggle.

Treat focus inside the dialog as no focus, so the aria-controls fallback
finds the real toggle.

Tests: the SSR test's showModal() mock now moves focus into the dialog
like the native method, and a new case covers an unfocused toggle whose
aria-controls names the drawer.

* Merge branch 'fix/rtl-mobile-sidenav-first-open' of https://github.com/mahmed74/astryx into fix/rtl-mobile-sidenav-first-open

* feedback

* latest feedback

* test(MobileNav): restore the Chromium entrance-edge spec for side="auto"

The spec checks in real Chromium that the drawer enters from the edge beside
its opener, in LTR and RTL, with the opener in either half of the viewport.
A branch merge had dropped it; it returns unchanged, from #11282.

Co-authored-by: Josh <[email protected]>
Co-authored-by: mahmed74 <[email protected]>

* test(MobileNav): the entrance-edge spec sets RTL through the Storybook global and checks where the drawer settles

The RTL cases set dir only on #storybook-root, inside which the Storybook
decorator lays the drawer out LTR, so they passed with the drawer on the far
side. The spec now loads each case with the direction global and also checks
that the settled drawer sits in its opener's half of the viewport. In real
Chromium all four cases pass on this branch; on main three fail.

Co-authored-by: Josh <[email protected]>
Co-authored-by: mahmed74 <[email protected]>

* Merge branch 'main' into fix/rtl-mobile-sidenav-first-open

* fix(MobileNav): a centred opener keeps side="auto" mirrored in RTL

The auto side counted an opener at the exact centre as the right half in
both directions, so a centred toggle opened the drawer on the right edge in
LTR and in RTL. The check now tests the inline-start half for the opener's
direction, so a centred opener opens at the inline end in both: the right
edge in LTR and the left edge in RTL. A unit case covers a centred opener in
each direction.

Co-authored-by: ahmed-technyx <[email protected]>

* ci feedback

* chore(lint): the comment-provenance baseline drops the MobileNav comment this change removed

MobileNav.tsx now has one fewer comment that cites an issue, so the
no-comment-provenance baseline lists two of those sites instead of three,
as the baseline script writes it.

Co-authored-by: ahmed-technyx <[email protected]>

* Merge branch 'main' into fix/rtl-mobile-sidenav-first-open

* Merge branch 'main' into fix/rtl-mobile-sidenav-first-open

Co-authored-by: Cindy Zhang <[email protected]>
@cixzhang

Copy link
Copy Markdown
Contributor

(Posted by Cindy's agent.) Thank you for this fix, @bezabyte! #11227 fixed the same right-to-left drawer bug and has now merged; it also covers every later open, not just the first, so I'm closing this one in favor of it. We appreciate the help.

@cixzhang cixzhang closed this Nov 13, 2026

This branch was successfully deployed

1 active deployment
Preview — c2d7ab2c Deployed Nov 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] RTL mobile navbar/sidebar opens in the wrong direction on first attempt

3 participants