Skip to content

Commit cda2264

Browse files
committed
fix: dismiss non-important modal when click outside, fix #1468
Signed-off-by: Innei <i@innei.in>
1 parent a3eb287 commit cda2264

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

apps/renderer/src/components/ui/modal/stacked/modal.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export const ModalInternal = memo(
241241
<Dialog.Content
242242
asChild
243243
aria-describedby={undefined}
244-
onPointerDownOutside={(event) => event.preventDefault()}
244+
onPointerDownOutside={preventDefault}
245245
onOpenAutoFocus={openAutoFocus}
246246
>
247247
<div
@@ -291,7 +291,6 @@ export const ModalInternal = memo(
291291
<Dialog.Content
292292
asChild
293293
aria-describedby={undefined}
294-
// @ts-expect-error
295294
onPointerDownOutside={preventDefault}
296295
onOpenAutoFocus={openAutoFocus}
297296
>

apps/renderer/src/components/ui/modal/stacked/provider.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@ const ModalStack = () => {
3232
const overlayOptions = stack[overlayIndex]?.overlayOptions
3333

3434
const hasModalStack = stack.length > 0
35+
const topModalIsNotSetAsAModal = topModalIndex !== stack.length - 1
3536

3637
useEffect(() => {
3738
// NOTE: document.body is being used by radix's dismissable,
3839
// and using that will cause radix to get the value of `none` as the store value,
3940
// and then revert to `none` instead of `auto` after a modal dismiss.
40-
document.documentElement.style.pointerEvents = hasModalStack ? "none" : "auto"
41+
document.documentElement.style.pointerEvents =
42+
hasModalStack && !topModalIsNotSetAsAModal ? "none" : "auto"
4143
document.documentElement.dataset.hasModal = hasModalStack.toString()
42-
}, [hasModalStack])
44+
}, [hasModalStack, topModalIsNotSetAsAModal])
4345
return (
4446
<AnimatePresence mode="popLayout">
4547
{stack.map((item, index) => (

packages/utils/src/dom.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import type { ReactEventHandler } from "react"
1+
export const stopPropagation = <T extends { stopPropagation: () => any }>(e: T) =>
2+
e.stopPropagation()
23

3-
export const stopPropagation: ReactEventHandler<any> = (e) => e.stopPropagation()
4-
5-
export const preventDefault: ReactEventHandler<any> = (e) => e.preventDefault()
4+
export const preventDefault = <T extends { preventDefault: () => any }>(e: T) => e.preventDefault()
65

76
export const nextFrame = (fn: (...args: any[]) => any) => {
87
requestAnimationFrame(() => {

0 commit comments

Comments
 (0)