Skip to content

Commit

Permalink
fix: call transition end on test envs after on exit only
Browse files Browse the repository at this point in the history
before theoretically it may be called on mount as well
  • Loading branch information
khmm12 committed Jun 24, 2024
1 parent a51b1f3 commit 1c65c8e
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createEffect, type JSX, Show, useContext } from 'solid-js'
import { createEffect, type JSX, on, Show, useContext } from 'solid-js'
import { Portal } from 'solid-js/web'
import { Transition } from 'solid-transition-group'
import { CloseIcon } from '@/components/Icon'
Expand All @@ -20,13 +20,21 @@ export default function Modal(props: ModalProps): JSX.Element {

const transition = useContext(ShowWithTransitionContext)

createEffect(() => {
// Emulate transition end event in test environment
if (import.meta.env.TEST && !transition.isOpened)
setTimeout(() => {
transition.onAfterExit()
}, 0)
}, transition.isOpened)
// Emulate transition end event in test environment
if (import.meta.env.TEST) {
createEffect(
on(
() => transition.isOpened,
(isOpened) => {
if (!isOpened)
setTimeout(() => {
transition.onAfterExit()
}, 0)
},
{ defer: true },
),
)
}

useDialogHooks({
get $overlay() {
Expand Down

0 comments on commit 1c65c8e

Please sign in to comment.