Skip to content

Commit 8353aeb

Browse files
committed
refactor(modal): call onShow$ & onClose$ in Modal directly
1 parent cc6516a commit 8353aeb

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

packages/kit-headless/src/components/modal/modal-behavior.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QRL, QwikMouseEvent } from '@builder.io/qwik';
1+
import { QwikMouseEvent } from '@builder.io/qwik';
22
import { FocusTrap, createFocusTrap } from 'focus-trap';
33

44
export type WidthState = {
@@ -36,20 +36,18 @@ export function deactivateFocusTrap(focusTrap: FocusTrap | null) {
3636
* Applies a CSS-Class to animate the modal-showing.
3737
* Calls the given callback that is executed after the Modal has been opened.
3838
*/
39-
export async function showModal(modal: HTMLDialogElement, onShow$?: QRL<() => void>) {
39+
export async function showModal(modal: HTMLDialogElement) {
4040
modal.showModal();
4141
supportShowAnimation(modal);
42-
await onShow$?.();
4342
}
4443

4544
/**
4645
* Closes the given Modal.
4746
* Applies a CSS-Class to animate the Modal-closing.
4847
* Calls the given callback that is executed after the Modal has been closed.
4948
*/
50-
export async function closeModal(modal: HTMLDialogElement, onClose$?: QRL<() => void>) {
49+
export async function closeModal(modal: HTMLDialogElement) {
5150
supportClosingAnimation(modal, () => modal.close());
52-
await onClose$?.();
5351
}
5452

5553
/**

packages/kit-headless/src/components/modal/modal.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ export const Modal = component$((props: ModalProps) => {
5757
window.addEventListener('keydown', escapeKeydownHandler);
5858

5959
if (isOpen) {
60-
showModal(modal, props.onShow$);
60+
showModal(modal);
61+
props.onShow$?.();
6162
adjustScrollbar(scrollbar, modal);
6263
activateFocusTrap(focusTrap);
6364
lockScroll();
6465
} else {
6566
unlockScroll(scrollbar);
6667
closeModal(modal);
67-
// animateClosing(modal, props.onClose$);
68+
props.onClose$?.();
6869
}
6970

7071
cleanup(() => {

0 commit comments

Comments
 (0)