Skip to content

Commit 6d595bd

Browse files
fix: modal scroll remains locked until the 1st level modal is closed
1 parent 3c34774 commit 6d595bd

File tree

10 files changed

+319
-349
lines changed

10 files changed

+319
-349
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { PropsOf, component$, useSignal, useStyles$ } from '@builder.io/qwik';
2+
import { Modal } from '@qwik-ui/headless';
3+
import styles from '../snippets/animation.css?inline';
4+
5+
export default component$(() => {
6+
const showSig = useSignal(false);
7+
useStyles$(styles);
8+
9+
return (
10+
<>
11+
<button
12+
onClick$={() => {
13+
showSig.value = true;
14+
}}
15+
class="rounded-base border px-3 py-2 hover:bg-accent/80"
16+
>
17+
Open Modal
18+
</button>
19+
<Modal bind:show={showSig} class="my-animation">
20+
Inside the modal!
21+
</Modal>
22+
</>
23+
);
24+
});
25+
26+
export function CloseIcon(props: PropsOf<'svg'>, key: string) {
27+
return (
28+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props} key={key}>
29+
<path
30+
fill="currentColor"
31+
d="m12 13.4l2.9 2.9q.275.275.7.275t.7-.275q.275-.275.275-.7t-.275-.7L13.4 12l2.9-2.9q.275-.275.275-.7t-.275-.7q-.275-.275-.7-.275t-.7.275L12 10.6L9.1 7.7q-.275-.275-.7-.275t-.7.275q-.275.275-.275.7t.275.7l2.9 2.9l-2.9 2.9q-.275.275-.275.7t.275.7q.275.275.7.275t.7-.275l2.9-2.9Zm0 8.6q-2.075 0-3.9-.788t-3.175-2.137q-1.35-1.35-2.137-3.175T2 12q0-2.075.788-3.9t2.137-3.175q1.35-1.35 3.175-2.137T12 2q2.075 0 3.9.788t3.175 2.137q1.35 1.35 2.138 3.175T22 12q0 2.075-.788 3.9t-2.137 3.175q-1.35 1.35-3.175 2.138T12 22Zm0-2q3.35 0 5.675-2.325T20 12q0-3.35-2.325-5.675T12 4Q8.65 4 6.325 6.325T4 12q0 3.35 2.325 5.675T12 20Zm0-8Z"
32+
></path>
33+
</svg>
34+
);
35+
}

apps/website/src/routes/docs/headless/modal/examples/animation.tsx

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
2+
import { Modal } from '@qwik-ui/headless';
3+
import styles from '../snippets/modal.css?inline';
4+
5+
export default component$(() => {
6+
useStyles$(styles);
7+
const isOpen = useSignal(false);
8+
9+
return (
10+
<>
11+
<button class="modal-trigger" onClick$={() => (isOpen.value = true)}>
12+
Open Modal
13+
</button>
14+
<Modal class="modal" bind:show={isOpen}>
15+
Modal Content
16+
<input placeholder="inside input" />
17+
<button>inside button</button>
18+
</Modal>
19+
<input placeholder="outside input" />
20+
</>
21+
);
22+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
2+
import { Modal } from '@qwik-ui/headless';
3+
import styles from '../snippets/modal.css?inline';
4+
5+
export default component$(() => {
6+
useStyles$(styles);
7+
const isOpen = useSignal(false);
8+
9+
return (
10+
<>
11+
<button class="modal-trigger" onClick$={() => (isOpen.value = true)}>
12+
Open Modal
13+
</button>
14+
<Modal class="modal" bind:show={isOpen}>
15+
Modal Content
16+
<NestedModal />
17+
</Modal>
18+
</>
19+
);
20+
});
21+
22+
export const NestedModal = component$(() => {
23+
useStyles$(styles);
24+
const isNestedOpen = useSignal(false);
25+
26+
return (
27+
<>
28+
<button class="modal-trigger" onClick$={() => (isNestedOpen.value = true)}>
29+
Nested Modal Trigger
30+
</button>
31+
<Modal class="modal" bind:show={isNestedOpen}>
32+
Nested Modal Content
33+
</Modal>
34+
</>
35+
);
36+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
2+
import { Modal } from '@qwik-ui/headless';
3+
import styles from '../snippets/modal.css?inline';
4+
5+
export default component$(() => {
6+
useStyles$(styles);
7+
const isOpen = useSignal(false);
8+
9+
return (
10+
<div style={{ height: '200vh' }}>
11+
<button class="modal-trigger" onClick$={() => (isOpen.value = true)}>
12+
Open Modal
13+
</button>
14+
<Modal class="modal" bind:show={isOpen}>
15+
Modal Content
16+
</Modal>
17+
</div>
18+
);
19+
});

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export type WidthState = {
44
width: number | null;
55
};
66

7-
import { clearAllBodyScrollLocks } from 'body-scroll-lock-upgrade';
7+
import { enableBodyScroll } from 'body-scroll-lock-upgrade';
88

99
/**
1010
* Traps the focus of the given Modal
@@ -101,7 +101,7 @@ export function supportClosingAnimation(modal: HTMLDialogElement) {
101101
'animationend',
102102
() => {
103103
modal.classList.remove('modal-closing');
104-
clearAllBodyScrollLocks();
104+
enableBodyScroll(modal);
105105
modal.close();
106106
},
107107
{ once: true },
@@ -112,15 +112,15 @@ export function supportClosingAnimation(modal: HTMLDialogElement) {
112112
'transitionend',
113113
() => {
114114
modal.classList.remove('modal-closing');
115-
clearAllBodyScrollLocks();
115+
enableBodyScroll(modal);
116116
modal.close();
117117
},
118118
{ once: true },
119119
);
120120
}
121121
if (animationDuration === '0s' && transitionDuration === '0s') {
122122
modal.classList.remove('modal-closing');
123-
clearAllBodyScrollLocks();
123+
enableBodyScroll(modal);
124124
modal.close();
125125
}
126126
}

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

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)