Skip to content

Commit

Permalink
fix: dismiss non-important modal when click outside, fix #1468
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Nov 10, 2024
1 parent a3eb287 commit cda2264
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
3 changes: 1 addition & 2 deletions apps/renderer/src/components/ui/modal/stacked/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export const ModalInternal = memo(
<Dialog.Content
asChild
aria-describedby={undefined}
onPointerDownOutside={(event) => event.preventDefault()}
onPointerDownOutside={preventDefault}
onOpenAutoFocus={openAutoFocus}
>
<div
Expand Down Expand Up @@ -291,7 +291,6 @@ export const ModalInternal = memo(
<Dialog.Content
asChild
aria-describedby={undefined}
// @ts-expect-error
onPointerDownOutside={preventDefault}
onOpenAutoFocus={openAutoFocus}
>
Expand Down
6 changes: 4 additions & 2 deletions apps/renderer/src/components/ui/modal/stacked/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ const ModalStack = () => {
const overlayOptions = stack[overlayIndex]?.overlayOptions

const hasModalStack = stack.length > 0
const topModalIsNotSetAsAModal = topModalIndex !== stack.length - 1

useEffect(() => {
// NOTE: document.body is being used by radix's dismissable,
// and using that will cause radix to get the value of `none` as the store value,
// and then revert to `none` instead of `auto` after a modal dismiss.
document.documentElement.style.pointerEvents = hasModalStack ? "none" : "auto"
document.documentElement.style.pointerEvents =
hasModalStack && !topModalIsNotSetAsAModal ? "none" : "auto"
document.documentElement.dataset.hasModal = hasModalStack.toString()
}, [hasModalStack])
}, [hasModalStack, topModalIsNotSetAsAModal])
return (
<AnimatePresence mode="popLayout">
{stack.map((item, index) => (
Expand Down
7 changes: 3 additions & 4 deletions packages/utils/src/dom.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { ReactEventHandler } from "react"
export const stopPropagation = <T extends { stopPropagation: () => any }>(e: T) =>
e.stopPropagation()

export const stopPropagation: ReactEventHandler<any> = (e) => e.stopPropagation()

export const preventDefault: ReactEventHandler<any> = (e) => e.preventDefault()
export const preventDefault = <T extends { preventDefault: () => any }>(e: T) => e.preventDefault()

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

0 comments on commit cda2264

Please sign in to comment.