Modals stay modal (page inert, scrim live) for the whole exit animation: the first click after an outside dismissal is lost
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 55/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- typescript
- 領域
- accessibility, frontend, testing
研究方向
Start with components/Dialog/Dialog.svelte, primitives/presence.svelte.js, and primitives/layer.js to trace how closing state, animation completion, modal behavior, focus, and scroll locking interact. Reproduce the lost click using the provided Playwright timing steps, then inspect the ModalContract browser test mentioned in the issue. Done means a click shortly after dismissal reaches the page button and a nonterminating descendant animation cannot keep the dialog modal; the issue does not name exact test paths.
由索引模型根據 Issue 內容生成。
描述
What happens
A modal (Dialog, AlertDialog, Drawer, Sheet, CommandPalette) is closed by pressing outside it (or Escape, or a button). The user then clicks a button on the page behind it right away: the click does nothing, a second click is needed. The cursor looks stuck.
Measured on WebKit (Playwright 1.65 WebKit, headless, real mouse events; @codeatlasdev/ui 4.6.0), a click on a page button N ms after the dismissal:
| ms after dismissal | button handler runs |
|---|---|
| 30, 80 | no (press lost) |
| 150, 250, 400 | yes |
The same on Chromium (30 ms: lost). It is the whole 150 ms exit animation (--ca-enter-fast).
Root cause (installed 4.6.0, dist/)
Closing only flips data-state="closed"; the layer stays alive, still modal, until the exit animation finishes:
components/Dialog/Dialog.svelte:109,118createPresence(() => open)/{#if presence.present}: the<dialog>stays rendered whileexiting.primitives/presence.svelte.js:16-46(exiting = true, rAF, thenPromise.allSettled(anims.map(a => a.finished))at line 40):exitingonly clears when every running animation, in the whole subtree, has finished.primitives/layer.js:435-436dialog.showModal()and:460-466dialog.close()run only in the layer'sclose(), which the owner calls when the{#if}branch is destroyed, i.e. after the exit. Until then the dialog is a modal: the rest of the page is inert (HTML "blocked by a modal dialog") and::backdrop(dialog.css:51) still takes the pointer. A press on the page goes to the closing dialog:layer.js:451-456onClickcallsonDismissagain (a no-op) and the click never reaches the button.layer.js:25-35: a closing entry is skipped bytopInteractive/topModal, so the kit already treats the layer as "closing"; only the platform state (modal, inert, focus traplayer.js:434, scroll lock:432) is not released.
Side effect of the same line: an animation that never ends inside the dialog (a spinner with animation-iteration-count: infinite) makes Promise.allSettled wait forever, so the dialog never leaves (and stays modal).
Minimal reproduction
<script>
import { Dialog, Button } from "@codeatlasdev/ui";
let open = $state(false), n = $state(0);
</script>
<Button onclick={() => (open = true)}>Open</Button>
<Button id="other" onclick={() => n++}>Other {n}</Button>
<Dialog bind:open title="Dialog">hello</Dialog>
Open the dialog, press the scrim, and press #other within 150 ms (Playwright: page.mouse.click(scrim), page.waitForTimeout(30), page.mouse.click(other)): n stays 0.
Expected
A layer that has started closing must not intercept input: the page answers the first click after a dismissal, at any time.
Proposed fix
When a modal layer starts closing (closing() turns true in modalLayer), release the platform side at once and keep only the visual exit: release the focus trap and the scroll lock, dialog.close() then dialog.show() (non-modal, no ::backdrop, no inert page; re-focus the previously focused element after show() because it moves focus into the dialog) and draw the scrim fade with the dialog's own box-shadow spread, or fade a non-interactive sibling. pointer-events: none on [data-state="closed"] for the panel. Independently: in presence.svelte.js ignore animations whose effect.getComputedTiming().endTime is Infinity.
Also add a browser test (ModalContract-style): dismiss by scrim, click a page button 0/30/80 ms later, expect one handler call each.
Workaround in Atlas
codeatlasdev/atlas#501: one document-level observer finishes the exit animation of any closing dialog.ca-overlay (the kit then drops the layer the next frame), plus .ca-floating[data-state="closed"] { pointer-events: none }. Documented with the removal condition in docs/desktop.md ("UI kit workarounds"). Atlas will delete it when a kit release passes its regression test without it.
- 主要語言
- TypeScript
- 星號
- 6
- 分支
- 3
- 平均合併
- 5 小時 21 分鐘
- 30 天內合併 PR
- 378
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
codeatlasdev/ui 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 84/100
codeatlasdev/ui#1340 ·
維護者通常 1 天內回覆
-
area:a11y area:components bug
難度 2/5 1-3 小時 新手友好度 76/100
codeatlasdev/ui#1336 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 77/100
codeatlasdev/ui#1329 ·
維護者通常 1 天內回覆
-
good first issue
難度 2/5 1-3 小時 新手友好度 74/100
codeatlasdev/ui#1292 · 1 則留言 ·
維護者通常 1 天內回覆
-
area:components enhancement good first issue
難度 2/5 1-3 小時 新手友好度 68/100
codeatlasdev/ui#1198 ·
維護者通常 1 天內回覆
相似的 Issue
-
bug frontend
難度 2/5 1-3 小時 新手友好度 85/100
CivicTechWR/accessible-housing-portal#578 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
nekko-labs/nekko-agent#2998 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 86/100
sandbox-quantum/switch#2163 ·
維護者通常 1 天內回覆
-
enhancement ux
難度 2/5 1-3 小時 新手友好度 72/100
lolimmlost/aidj#433 ·
維護者通常 1 天內回覆
-
test: ipcShownDialogKeys.test.tsx can fail the unit run with 'window is not defined' after it ends未關閉
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆