Repository navigation
fix(MobileNav): side="auto" resolves the drawer edge in RTL and on first open - #11227
Conversation
…L 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 meta#11206
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Hi @mahmed74! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
AI review status for this pull request.
|
There was a problem hiding this comment.
Thanks for digging into #11206. Requesting changes: right-to-left drawers now settle on the opener's side, but the first-open problem is still there for some openers, and two smaller fixes are needed.
- The first open still slides in from the far edge when the opener sits in the inline-start half of an RTL page, because the side is set in the Effect after the drawer has already rendered with the default
end(in Chromium the drawer starts off-screen left and then jumps to the right edge, while the second open is correct), so please resolve the side before the drawer's first rendered frame and cover the first open's entrance with a browser test. - The unfocused fallback compares
aria-controlswith the internal drawer id (MobileNav.tsx:577-579), so a standaloneMobileNavwith its ownidand an opener that names it still opens fromend; please match eacharia-controlstoken against the dialog's rendered id as well and add a test for that case. MobileNav.tsx:584re-implementsisRtlElementfromhooks/isRtlElement.ts; please callisRtlElement(trigger)so Core reads direction in one place.
In Chromium the toggle is focused after both a click and a tap, so the focus fallback alone does not explain the reported first open. A shorter comment above the fallback, and a description that says later RTL opens were also on the far side before this change, would help reviewers.
Address review feedback on meta#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.
There was a problem hiding this comment.
Thanks for the quick follow-up: the first right-to-left open now enters from the opener's side, and the caller id and isRtlElement points are fixed. Requesting changes for two remaining issues:
- A
side="auto"drawer that is already open when server-rendered markup hydrates reads focus and layout in the hydrating render, so React reports an attribute mismatch it does not patch and the drawer stays on the server's inline-end edge with a staledata-side(MobileNav.tsx:559-584); please keep those reads out of the hydrating render (asTimestamp.tsxdoes withuseSyncExternalStore), resolve an already-open drawer after hydration, and add a server-render-then-hydrate test likeDrawer.ssr.test.tsx. - CI runs ESLint in strict mode, where
MobileNav.tsx:573fails@eslint-react/purityfordocument.querySelectorAllduring render andMobileNavAutoSideRtl.test.tsx:119fails@typescript-eslint/array-type(use(string | null | undefined)[]).
With this change AppShell's right-to-left drawer opens from the left edge, beside its toggle, on every open, as the MobileNav record's FR8 asks. The comment above the opener lookup and the description's "Later opens are correct" could also be tightened; the inline comments have details.
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.
There was a problem hiding this comment.
Requesting changes for one remaining issue. Thanks for the follow-up: a drawer that is open on the server now hydrates without a mismatch, the strict-lint errors are gone, and right-to-left drawers open beside their opener from the first open in Chromium.
MobileNav.tsx:302-304and:568-572rebuild theuseSyncExternalStorehydration flag thatuseIsHydrating(packages/core/src/hooks/useIsHydrating.ts) already owns for Drawer, Dialog, BottomSheet and the rest of Core; please useconst canReadDom = !useIsHydrating();and delete the three module constants and theuseSyncExternalStoreimport, which also putsCLOSE_WITHIN_HOLDback under its own JSDoc.
The earlier review pointed to Timestamp.tsx, which keeps its own copy; useIsHydrating is the shared owner. The inline comments suggest shorter wording for two code comments, and the description's "Later opens are correct", "No ... visual change" and test counts are out of date: AppShell's right-to-left drawer now opens from the left edge, beside its toggle, on every open.
…ration 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]>
|
/approve-spec 39318a7 |
|
/approve-spec 94ba966 |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet, so a maintainer needs to add the ci:run label to run it.
Thanks for the follow-ups. Right-to-left side="auto" drawers now open beside their opener from the first open, a drawer that is already open when the page hydrates no longer causes a mismatch, and the shared useIsHydrating hook now gates the read. One optional comment-wording suggestion is inline.
Claims and files checked
Claims
- The first right-to-left open after a page load slid in from the wrong edge: verified. The base set the edge in an Effect after the opening commit, so
showModal()ran with the defaultend. - Later right-to-left opens also landed on the far side, and every open now resolves from the opener: verified (
MobileNav.tsx:582-584). - The fix affects the default
side="auto", including AppShell's drawer: verified (MobileNav.tsx:494). - With nothing focused, the drawer kept its default
end, which is the left edge in right-to-left: verified (base Effect;drawerEndusesinsetInlineEnd). - The left-half check ignored text direction: verified (base Effect).
- The edge arrived one commit after the open render: verified (base Effect order; the test that reads
data-sideatshowModal()). - The fix resolves the edge relative to text direction before the first frame: verified (
MobileNav.tsx:557-588). - With nothing focused, the element whose
aria-controlsnames the drawer is used, matching each token, so a calleridresolves: verified (MobileNav.tsx:566-578; caller-idtest). - The fix uses the existing
isRtlElementhelper: verified (MobileNav.tsx:84,:584). - A drawer that is open when it hydrates reads no focus or layout until after hydration, with no mismatch: verified (
MobileNav.tsx:560-561, through the shareduseIsHydrating; SSR test). The description's Timestamp reference is now this shared hook. - No new API, prop, attribute or default: verified (source diff). "No visual change" holds for styling. The right-to-left resting edge does move, and that move is the fix.
- Before the change, a right-to-left inline-start opener and an unfocused first open resolved to
end. After it, both resolve tostart, and a focused left-to-right opener is unchanged: verified (base and head code; the new tests). - All 14 MobileNav test files pass: the 14 files are confirmed, and CI confirms the run on this head.
- The SSR test fails without the hydration gate: verified on the earlier revision without the gate.
- Changeset (core patch:
side="auto"opens from the opener's inline edge in right-to-left, including an unfocused first open): verified (MobileNav.tsx:561-588; the new tests).
Files
.changeset/mobilenav-auto-side-rtl.md: clear.packages/core/src/MobileNav/MobileNav.tsx: clear, plus one optional comment suggestion (:554-556).packages/core/src/MobileNav/MobileNavAutoSideRtl.test.tsx: clear.packages/core/src/MobileNav/MobileNavAutoSideSsr.test.tsx: clear.
There was a problem hiding this comment.
Requesting changes for one remaining issue. Right-to-left side="auto" drawers now open beside their opener from the first open, the dialog and its contents stay mounted across opening, and a drawer that is open in the server markup hydrates without a mismatch.
- Miss: after a drawer that was open in the server markup hydrates, the lookup at
MobileNav.tsx:566-570runs aftershowModal()has moved focus into the drawer, so it measures the drawer panel instead of the opener and skips thearia-controlsfallback; treat focus inside the dialog as no focus, and make the SSR test'sshowModal()mock move focus into the drawer asMobileNavFocus.test.tsxdoes, asserting that the side still follows the opener.
Optionally, #11282 has a Chromium spec that checks the entrance edge in LTR and RTL from both halves of the viewport, and adopting it with credit to its author would cover the entrance in a real browser. CI has not run on this head yet; a maintainer adds the ci:run label so it runs.
Claims and files checked
Claims
- Right-to-left drawers opened on the far side because the edge check ignored text direction: verified from the previous code.
- With nothing focused, the first open fell back to the default
endedge: verified from the previous code. - Every open now resolves from the opener: verified for opens in the page; false after a server-open drawer hydrates (the finding above).
- The default
side="auto"is affected, including the AppShell drawer: verified (MobileNav.tsx:494). - The edge is set before the first rendered frame: verified (
MobileNav.tsx:557-588; the test that readsdata-sideatshowModal()). - With nothing focused, the element whose
aria-controlsnames the drawer is the opener, and a calleridresolves: verified (MobileNav.tsx:564-578; the caller-idtest). - The existing direction helper is used: verified (
MobileNav.tsx:584). - A drawer open on the server reads no focus or layout while hydrating, with no mismatch: verified (
MobileNav.tsx:560-561; the SSR test). - No new API, prop, attribute or default: verified.
- Before the change an inline-start RTL opener and an unfocused first open resolved to
end, after it tostart, and a focused inline-start LTR opener is unchanged: verified from the previous and new code. - The SSR test resolves from the opener after hydration: false outside jsdom, because its
showModal()mock does not move focus. - The SSR test fails without the hydration gate: consistent with the code.
- The MobileNav, AppShell and hook suites pass: not verified, since CI has not run on this head.
- The latest commit changes only code comments: verified.
- Changeset (core patch: opens from the opener's inline edge in RTL, including the first open after a page load with no focus): verified for opens in the page.
Files
.changeset/mobilenav-auto-side-rtl.md: clear.packages/core/src/MobileNav/MobileNav.tsx: the finding above (:560-570); one open comment-wording suggestion (:554-556).packages/core/src/MobileNav/MobileNavAutoSideRtl.test.tsx: clear.packages/core/src/MobileNav/MobileNavAutoSideSsr.test.tsx: itsshowModal()mock omits the native focus move (part of the finding above).
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]>
…n 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.
|
/approve-spec 120056d |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet.
The ci:run label is already applied, but the workflow runs for this head are waiting for a maintainer to approve them; CI starts once they do.
Thanks for adding the contributor line: the changeset now passes the repository's changeset check, and the change keeps a right-to-left side="auto" drawer beside its opener, the first open included, with unit and SSR tests that fail without the fix.
Non-blocking: the open comment-style threads on MobileNav.tsx and the side-change case's focus setup in MobileNavAutoSideRtl.test.tsx are still worth a pass.
Claims and files checked
Claims:
- Right-to-left drawers opened from an off-centre opener came in from the far edge on every open in Chromium: verified (base Chromium capture, both halves).
- With nothing focused the first open fell back to
end, and the edge was set one commit after the open: verified (the unfocused and opening-commit cases fail on the base). - Every open now resolves from a focused opener or one whose
aria-controlsnames the drawer; a plain unfocused opener still getsend: verified (MobileNav.tsx:566-596). - The fallback matches each
aria-controlstoken against the rendered id, so a calleridstill resolves: verified (caller-id case). - The left half is the inline start in left-to-right and the inline end in right-to-left, and a centred opener opens at the end in both: verified (
MobileNav.tsx:590-596, centred cases). - The edge is resolved while rendering the open, so the first frame has it: verified (opening-commit case).
- A drawer open in server markup reads nothing while hydrating and hydrates with no mismatch, and the test fails without the hydration gate: verified (SSR case 1, mutation run).
- Both SSR cases assert the drawer is never measured and fail without the focus guard: verified (mutation run).
- No new API, prop, attribute or default: verified (built API surface comparison shows no change).
- The MobileNav and AppShell tests are 18 files and 201 tests at this head: verified (test run).
- The Chromium spec checks the entrance edge in both directions from both halves and credits #11282: verified (spec contents, co-author trailers).
- The stills: the AppShell toggle is in the right half, the drawer rests at x 0–320 before and x 70–390 after, and the product code since the stills changes only how a centred opener resolves: verified (Chromium capture, diff since that commit).
- The Default story centres its toggle and its right-to-left drawer rests where it does on
main: verified (story layout, centred cases). - Changeset:
MobileNavTogglesetsaria-controls, and a custom opener without it that never takes focus still opens fromend: verified (MobileNavToggle.tsx:107). - Changeset: credits
@mahmed74as its contributor: verified (changeset check passes).
Files:
.changeset/mobilenav-auto-side-rtl.md: clearpackages/core/src/MobileNav/MobileNav.tsx: non-blocking comment-style notespackages/core/src/MobileNav/MobileNavAutoSideRtl.test.tsx: non-blocking note on the side-change casepackages/core/src/MobileNav/MobileNavAutoSideSsr.test.tsx: clearpackages/core/src/MobileNav/__tests__/MobileNavAutoSide.a11y.chromium.spec.ts: clear
…ent 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]>
|
/approve-spec f61c5b8 |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet.
The ci:run label is already applied, but the workflow runs for this head are waiting for a maintainer to approve them; CI starts once they do.
The lint baseline update clears the comment-provenance check that failed on the previous head, and the change keeps a right-to-left side="auto" drawer beside its opener, the first open included, with unit and SSR tests that fail without the fix.
Non-blocking: the open comment-style threads on MobileNav.tsx and the side-change case's focus setup in MobileNavAutoSideRtl.test.tsx are still worth a pass.
Claims and files checked
Claims:
- Right-to-left drawers opened from an off-centre opener came in from the far edge on every open in Chromium: verified (base Chromium capture, both halves).
- With nothing focused the first open fell back to
end, and the edge was set one commit after the open: verified (the unfocused and opening-commit cases fail on the base; base Chromium probe slides a start-side drawer in from the right). - Every open now resolves from a focused opener or one whose
aria-controlsnames the drawer; a plain unfocused opener still getsend: verified (MobileNav.tsx:566-596, Chromium unfocused capture). - The fallback matches each
aria-controlstoken against the rendered id, so a calleridstill resolves: verified (caller-id case). - The left half is the inline start in left-to-right and the inline end in right-to-left, and a centred opener opens at the end in both: verified (
MobileNav.tsx:590-596, centred cases). - The edge is resolved while rendering the open, so the first frame has it: verified (opening-commit case, Chromium entrance probes).
- A drawer open in server markup reads nothing while hydrating and hydrates with no mismatch, and the test fails without the hydration gate: verified (SSR case 1, mutation run).
- Both SSR cases assert the drawer is never measured and fail without the focus guard: verified (mutation run).
- No new API, prop, attribute or default: verified (built API surface comparison shows no change).
- The MobileNav and AppShell tests are 18 files and 201 tests, with two AppShell cases from main and two centred-opener cases: verified (test run, history).
- The Chromium spec checks the entrance edge in both directions from both halves and credits #11282: verified (spec contents, co-author trailers, the four cases reproduced in Chromium).
- The stills: the AppShell toggle is in the right half, the drawer rests at x 0–320 before and x 70–390 after, and the product code since the stills changes only how a centred opener resolves: verified (Chromium capture, diff since that commit).
- The Default story centres its toggle and its right-to-left drawer rests where it does on
main: verified (story layout, centred cases). - Changeset:
MobileNavTogglesetsaria-controls, a custom opener without it that never takes focus still opens fromend, and the entry credits@mahmed74: verified (MobileNavToggle.tsx:107, changeset check passes).
Files:
.changeset/mobilenav-auto-side-rtl.md: clearinternal/eslint-plugin-astryx/no-comment-provenance.baseline.json: clearpackages/core/src/MobileNav/MobileNav.tsx: non-blocking comment-style notespackages/core/src/MobileNav/MobileNavAutoSideRtl.test.tsx: non-blocking note on the side-change casepackages/core/src/MobileNav/MobileNavAutoSideSsr.test.tsx: clearpackages/core/src/MobileNav/__tests__/MobileNavAutoSide.a11y.chromium.spec.ts: clear
|
/approve-spec 5e862c3 |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet.
The ci:run label is already applied, but the workflow runs for this head are waiting for a maintainer to approve them; CI starts once they do.
The merge from main leaves this pull request's own changes untouched, and a right-to-left side="auto" drawer still opens beside its opener, the first open included, with unit and SSR tests that fail without the fix.
Non-blocking: the open comment-style threads on MobileNav.tsx and the side-change case's focus setup in MobileNavAutoSideRtl.test.tsx are still worth a pass.
Claims and files checked
- Claim: right-to-left drawers opened from an off-centre opener came in from the far edge on every open in Chromium: verified (base Chromium captures, both halves).
- Claim: with nothing focused the first open fell back to
end, and the edge was set one commit after the open: verified (the unfocused and opening-commit cases fail on the base; the base slides a start-side drawer in from the right). - Claim: every open now resolves from a focused opener or one whose
aria-controlsnames the drawer, and a plain unfocused opener still getsend: verified (MobileNav.tsx:566-596, Chromium unfocused capture). - Claim: the fallback matches each
aria-controlstoken against the rendered id, so a calleridstill resolves: verified (caller-id case). - Claim: the left half is the inline start in left-to-right and the inline end in right-to-left, and a centred opener opens at the end in both: verified (
MobileNav.tsx:590-596, centred cases, direction mutation). - Claim: the edge is resolved while rendering the open, so the first frame has it: verified (opening-commit case, Chromium entrance probes).
- Claim: a drawer open in server markup reads nothing while hydrating, hydrates with no mismatch, and the test fails without the hydration gate: verified (SSR case 1, mutation run).
- Claim: both SSR cases assert the drawer is never measured and fail without the focus guard: verified (mutation run).
- Claim: no new API, prop, attribute or default: verified (built API surface comparison shows no change).
- Claim: the MobileNav and AppShell tests are 18 files and 201 tests: verified (test run).
- Claim: the Chromium spec checks the entrance edge in both directions from both halves and credits the earlier contribution: verified (spec contents, co-author trailers, its four cases reproduced in Chromium).
- Claim: in the stills the AppShell toggle is in the right half and the drawer rests at x 0-320 before and x 70-390 after, and the product code since the stills changes only how a centred opener resolves: verified (Chromium capture, diff since that commit).
- Claim: the Default story centres its toggle and its right-to-left drawer rests where it does on
main: verified (story layout, centred cases). - Claim (changeset):
MobileNavTogglesetsaria-controls, a custom opener without it that never takes focus still opens fromend, and the entry credits@mahmed74: verified (MobileNavToggle.tsx:107, changeset check passes). - File
.changeset/mobilenav-auto-side-rtl.md: clear - File
internal/eslint-plugin-astryx/no-comment-provenance.baseline.json: clear - File
packages/core/src/MobileNav/MobileNav.tsx: non-blocking comment-style notes - File
packages/core/src/MobileNav/MobileNavAutoSideRtl.test.tsx: non-blocking note on the side-change case - File
packages/core/src/MobileNav/MobileNavAutoSideSsr.test.tsx: clear - File
packages/core/src/MobileNav/__tests__/MobileNavAutoSide.a11y.chromium.spec.ts: clear
|
/approve-spec 56792db |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet.
The ci:run label is already applied, but the workflow runs for this head are waiting for a maintainer to approve them; CI starts once they do.
The merge from main leaves this pull request's own changes untouched, and a right-to-left side="auto" drawer still opens beside its opener, the first open included, with unit and SSR tests that fail without the fix.
Non-blocking: the open comment-style threads on MobileNav.tsx and the side-change case's focus setup in MobileNavAutoSideRtl.test.tsx are still worth a pass.
Claims and files checked
- Claim: right-to-left drawers opened from an off-centre opener came in from the far edge on every open in Chromium: verified (base Chromium captures, both halves).
- Claim: with nothing focused the first open fell back to
end, and the edge was set one commit after the open: verified (the unfocused and opening-commit cases fail on the base; the base slides a start-side drawer in from the right). - Claim: every open now resolves from a focused opener or one whose
aria-controlsnames the drawer, and a plain unfocused opener still getsend: verified (MobileNav.tsx:566-596, Chromium unfocused capture). - Claim: the fallback matches each
aria-controlstoken against the rendered id, so a calleridstill resolves: verified (caller-id case). - Claim: the left half is the inline start in left-to-right and the inline end in right-to-left, and a centred opener opens at the end in both: verified (
MobileNav.tsx:590-596, centred cases, direction mutation). - Claim: the edge is resolved while rendering the open, so the first frame has it: verified (opening-commit case, Chromium entrance probes).
- Claim: a drawer open in server markup reads nothing while hydrating, hydrates with no mismatch, and the test fails without the hydration gate: verified (SSR case 1, mutation run).
- Claim: both SSR cases assert the drawer is never measured and fail without the focus guard: verified (mutation run).
- Claim: no new API, prop, attribute or default: verified (built API surface comparison shows no change).
- Claim: the MobileNav and AppShell tests are 18 files and 201 tests: verified (test run).
- Claim: the Chromium spec checks the entrance edge in both directions from both halves and credits the earlier contribution: verified (spec contents, co-author trailers, its four cases reproduced in Chromium).
- Claim: in the stills the AppShell toggle is in the right half and the drawer rests at x 0-320 before and x 70-390 after, and the product code since the stills changes only how a centred opener resolves: verified (Chromium capture, diff since that commit).
- Claim: the Default story centres its toggle and its right-to-left drawer rests where it does on
main: verified (story layout, centred cases). - Claim (changeset):
MobileNavTogglesetsaria-controls, a custom opener without it that never takes focus still opens fromend, and the entry credits@mahmed74: verified (MobileNavToggle.tsx:107, changeset check passes). - File
.changeset/mobilenav-auto-side-rtl.md: clear - File
internal/eslint-plugin-astryx/no-comment-provenance.baseline.json: clear - File
packages/core/src/MobileNav/MobileNav.tsx: non-blocking comment-style notes - File
packages/core/src/MobileNav/MobileNavAutoSideRtl.test.tsx: non-blocking note on the side-change case - File
packages/core/src/MobileNav/MobileNavAutoSideSsr.test.tsx: clear - File
packages/core/src/MobileNav/__tests__/MobileNavAutoSide.a11y.chromium.spec.ts: clear
User impact
Phone users in a right-to-left layout see the navigation drawer slide in from the far edge, away from the control that opened it. In Chromium this happened on every open, because the edge check ignored text direction. In a browser that does not focus a tapped button, the first open also fell back to the default
end. Every open now resolves from the opener when the opener holds focus or names the drawer inaria-controls. An opener that holds no focus and has noaria-controlsstill opens fromend. This affectsMobileNavwith the defaultside="auto", including the AppShell mobile drawer. Reported in #11206.Problem and solution fit
side="auto"picks the drawer's edge from the focused element's position. On the first open nothing may be focused, because a touch tap does not focus a button in every mobile browser. The drawer then keeps its defaultend, which is the left edge in RTL. The left-half check also ignored text direction, and the edge was set one commit after the open render, so the drawer could cross the screen before settling.The fix resolves the side relative to the text direction, before the first rendered frame. When nothing is focused, it uses the element whose aria-controls names the drawer as the opener. A plain button without aria-controls can't be found this way, so an unfocused first open from it still uses end.
Expected behavior and authority
design:bidirectionalityDR7: layered surfaces keep their start/end relationship to the trigger.component:MobileNavFR8:side="auto"keeps the drawer's start/end relationship to the element that opened it.Smallest restoration
In
MobileNav.tsx, theside="auto"resolution now:aria-controlsnames the drawer when no element is focused, matching each token against the dialog's rendered id so a caller id still resolves;useIsHydratinghook), so the server markup is unchanged and there is no hydration mismatch.No new API, prop, attribute or default. The visible change is the fix: a right-to-left drawer with side="auto" now enters from the opener's side on every open from a focused opener or an aria-controls toggle such as AppShell's. A standalone plain button that takes no focus (for example, the Default story's) still falls back to end.
Evidence
end, and a first open with nothing focused resolved toend.start.start. The MobileNav and AppShell tests are 18 files and 201 tests at this head: main added two AppShell cases, and the centred-opener commit added two MobileNav cases.MobileNavAutoSideSsr.test.tsx(server render, then hydrate with no mismatch, then resolve from the opener). The SSR test fails when the hydration gate is removed. Both SSR cases also assert that the drawer and its panel are never measured; they fail when the focus-inside-dialog guard is removed.__tests__/MobileNavAutoSide.a11y.chromium.spec.tschecks the entrance edge in real Chromium, in LTR and RTL, with the opener in either half of the viewport (from fix(mobile-nav): resolve auto side before opening #11282, with co-author credit).Real Chrome stills (first open, RTL)
Chrome 157, page set to RTL, light theme. Each frame is the first open after a fresh load, about 90 ms into the slide. Before:
main. After: 643aaf3. The head since then changes only how a centred opener resolves, which the AppShell toggle, in the right half, does not reach.The AppShell toggle sits in the right (inline-start) half of the bar. The drawer's edge, measured every frame:
The MobileNav "Default" story centres its toggle (x 195 of 390). A centred opener opens at the inline end in both directions, so its RTL drawer rests at x 0 to 320, as on
main; a unit case pins it.Scope
Components: MobileNav
Testing
pnpm vitest run packages/core/src/MobileNav --project uiFixes #11206