Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/mobile-nav-close-like-uikit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[fix] Closing `MobileNav` now runs like an iOS dismissal from start to end. The scrim fades out over the whole slide-out instead of vanishing partway through, and inside `AppShell` the slide-out is no longer cut off at 300 ms. While the drawer slides out nothing takes a tap: not the page, and not the leaving drawer, whose links used to stay live. When the slide-out ends, the dialog closes, the page takes input again and focus returns to the element that opened the drawer.

@vjeux
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,17 @@ jobs:
--project chromium \
--output table-min-width-output

# Closing MobileNav works like a UIKit dismissal: the dialog stays modal
# and inert while the drawer slides out and the scrim fades, no tap
# lands until it ends, then focus returns to the opener. Top-layer
# modality, inertness and real taps only exist in a real engine.
- name: Run MobileNav close contract
run: |
pnpm exec playwright test \
packages/core/src/MobileNav/__tests__/MobileNavClose.a11y.chromium.spec.ts \
--project chromium \
--output mobile-nav-close-output

# A CodeBlock diff row's tint has to follow a long line to the end of its
# scroll width; jsdom has no layout, so only a real engine shows whether
# the paint stops at the viewport edge when the reader scrolls.
Expand Down
25 changes: 12 additions & 13 deletions packages/core/src/AppShell/AppShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {LayoutHeader} from '../Layout/LayoutHeader';
import {LayoutPanel} from '../Layout/LayoutPanel';
import {LayoutContent} from '../Layout/LayoutContent';
import {MobileNavToggle} from '../MobileNav/MobileNavToggle';
import {MAX_CLOSE_DELAY_MS as MOBILE_NAV_MAX_CLOSE_DELAY_MS} from '../MobileNav/MobileNav';
import {MAX_EXIT_MS as MOBILE_NAV_MAX_EXIT_MS} from '../MobileNav/MobileNav';
import {SideNavRenderContext} from '../SideNav/SideNavRenderContext';
import {TopNavRenderContext} from '../TopNav/TopNavRenderContext';
import {TopNavMobileContentContext} from '../TopNav/TopNavMobileContentContext';
Expand Down Expand Up @@ -83,16 +83,16 @@ const ActivityWrapper = HasActivity
const MAIN_CONTENT_ID = 'astryx-app-shell-main';

/**
* Extra time, on top of MobileNav's own worst-case close delay, that
* AppShell waits before flipping its `Activity` boundary to `'hidden'`.
* Extra time, on top of MobileNav's longest slide-out, that AppShell waits
* before flipping its `Activity` boundary to `'hidden'`.
*
* React's `Activity` hides its subtree with `display: none !important`
* synchronously in the same commit as the mode flip, and re-runs the
* cleanup of every effect inside it — which would otherwise clear
* MobileNav's own scheduled `dialog.close()` before it fires, or cut off
* its slide-out CSS transition before it plays (#5701). Waiting strictly
* longer than MobileNav's own cap, rather than the same duration, means
* this never turns into a race decided by browser timer-firing order.
* cleanup of every effect inside it — which would cut the drawer's
* slide-out off and clear MobileNav's own `dialog.close()` at its end
* (#5701). Waiting strictly longer than MobileNav's own cap, rather than the
* same duration, means this never turns into a race decided by browser
* timer-firing order.
*/
const ACTIVITY_HIDE_BUFFER_MS = 50;

Expand Down Expand Up @@ -540,10 +540,9 @@ export function AppShell({
const [uncontrolledMobileOpen, setUncontrolledMobileOpen] = useState(false);
const isMobileNavOpen = mobileNavConfig?.isOpen ?? uncontrolledMobileOpen;

// Holds the mobile nav's `Activity` boundary visible for a beat after a
// close, so MobileNav's own close effect gets a real chance to run its
// slide-out transition and schedule its delayed `dialog.close()` before
// Activity hides the subtree (#5701). Only the CLOSE is deferred: opening
// Holds the mobile nav's `Activity` boundary visible after a close, so the
// drawer's slide-out plays to its end and MobileNav closes its own dialog
// before Activity hides the subtree (#5701). Only the CLOSE is deferred: opening
// reads `isMobileNavOpen` directly below, so a controlled open is visible in
// the commit that carries it instead of one effect later.
const [isMobileNavCloseHeld, setIsMobileNavCloseHeld] =
Expand All @@ -560,7 +559,7 @@ export function AppShell({
const delayMs = window.matchMedia('(prefers-reduced-motion: reduce)')
.matches
? 0
: MOBILE_NAV_MAX_CLOSE_DELAY_MS + ACTIVITY_HIDE_BUFFER_MS;
: MOBILE_NAV_MAX_EXIT_MS + ACTIVITY_HIDE_BUFFER_MS;
const timeout = setTimeout(() => {
setIsMobileNavCloseHeld(false);
}, delayMs);
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/MobileNav/MobileNav.doc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const docs = {
name: 'onOpenChange',
type: '(isOpen: boolean) => void',
description:
'Called when the drawer visibility changes (backdrop click, Escape key, or close button). Inside AppShell, this is managed automatically via context.',
'Called when the drawer visibility changes (backdrop click, Escape key, or close button). Inside AppShell, this is managed automatically via context. On close the drawer slides out before anything takes input again, as on iOS; focus then returns to the element that opened it.',
},
{
name: 'children',
Expand Down Expand Up @@ -203,7 +203,7 @@ export const docsZh = {
name: 'onOpenChange',
type: '(isOpen: boolean) => void',
description:
'当抽屉可见性变化时调用(点击背景遮罩、按 Escape 键或点击关闭按钮)。',
'当抽屉可见性变化时调用(点击背景遮罩、按 Escape 键或点击关闭按钮)。关闭时抽屉先滑出,期间页面不接受输入(与 iOS 相同);随后焦点回到打开它的元素。',
required: true,
},
{
Expand Down Expand Up @@ -311,7 +311,7 @@ export const docsDense = {
propDescriptions: {
isOpen: 'whether drawer is open',
onOpenChange:
'called when drawer visibility changes (backdrop click, Escape, close button)',
'called when drawer visibility changes (backdrop click, Escape, close button); on close nothing takes input until the drawer has slid out, then focus returns to the opener',
children:
'drawer content; typically SideNavSection/SideNavItem or any ReactNode',
header:
Expand Down
Loading
Loading