Skip to content

Commit df46c87

Browse files
fix: failing test
1 parent 8f8a54f commit df46c87

File tree

5 files changed

+64
-20
lines changed

5 files changed

+64
-20
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { component$ } from '@builder.io/qwik';
2+
3+
export default component$(() => {
4+
return <div>Test Route</div>;
5+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export const api = {
2+
modal: [
3+
{
4+
'modal-close': [],
5+
},
6+
{
7+
'modal-content': [],
8+
},
9+
{
10+
'modal-context': [],
11+
},
12+
{
13+
'modal-description': [],
14+
},
15+
{
16+
'modal-footer': [],
17+
},
18+
{
19+
'modal-header': [],
20+
},
21+
{
22+
'modal-panel': [],
23+
},
24+
{
25+
'modal-root': [],
26+
},
27+
{
28+
'modal-title': [],
29+
},
30+
{
31+
'modal-trigger': [],
32+
},
33+
{
34+
'use-modal': [],
35+
},
36+
],
37+
};

apps/website/src/routes/docs/headless/modal/examples/test-spa-scroll.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default component$(() => {
2424
<Modal.Close class="modal-close">Cancel</Modal.Close>
2525
<Modal.Close class="modal-close">Save Changes</Modal.Close>
2626
</footer>
27-
<Link href="../hero">ACCORDON</Link>
27+
<Link href="../../../test-route">SPA NAVIGATION</Link>
2828
</Modal.Panel>
2929
</Modal.Root>
3030
);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { modalContextId } from './modal-context';
1616

1717
import styles from './modal.css?inline';
1818
import { useModal } from './use-modal';
19+
import { isServer } from '@builder.io/qwik/build';
20+
import { enableBodyScroll } from 'body-scroll-lock-upgrade';
1921

2022
export type ModalProps = Omit<PropsOf<'dialog'>, 'open'> & {
2123
onShow$?: QRL<() => void>;
@@ -59,7 +61,10 @@ export const HModalPanel = component$((props: PropsOf<'dialog'>) => {
5961
}
6062

6163
cleanup(async () => {
64+
if (isServer) return;
6265
await deactivateFocusTrap(focusTrap);
66+
if (!panelRef.value) return;
67+
enableBodyScroll(panelRef.value);
6368
});
6469
});
6570

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,22 @@ test.describe('Scroll locking', () => {
137137
}),
138138
).toBe(true);
139139
});
140+
141+
test(`GIVEN a modal
142+
WHEN navigating to another page in SPA
143+
THEN the body should not have overflow hidden`, async ({ page }) => {
144+
const { driver: d } = await setup(page, 'test-spa-scroll');
145+
146+
await expect(page.locator('body')).not.toHaveCSS('overflow', 'hidden');
147+
148+
await d.openModal();
149+
150+
await expect(page.locator('body')).toHaveCSS('overflow', 'hidden');
151+
152+
await page.click('[q\\:link]');
153+
154+
await expect(page.locator('body')).not.toHaveCSS('overflow', 'hidden');
155+
});
140156
});
141157

142158
test.describe('Focus Trap', () => {
@@ -167,25 +183,6 @@ test.describe('Focus Trap', () => {
167183
await insideButton.press('Tab');
168184
await expect(insideInput).toBeFocused();
169185
});
170-
171-
test(`GIVEN a modal
172-
WHEN navigating to another page in SPA
173-
THEN the body should not have overflow hidden`, async ({ page }) => {
174-
const { driver: d } = await setup(page, 'test-spa-scroll');
175-
176-
await expect(page.locator('body')).not.toHaveCSS('overflow', 'hidden');
177-
178-
await d.openModal();
179-
180-
await expect(page.locator('body')).toHaveCSS('overflow', 'hidden');
181-
182-
await Promise.all([
183-
page.waitForURL('**/headless/modal/hero/', { waitUntil: 'networkidle' }),
184-
page.click('[q\\:link]'),
185-
]);
186-
187-
await expect(page.locator('body')).not.toHaveCSS('overflow', 'hidden');
188-
});
189186
});
190187

191188
test.describe('Nested Modals', () => {

0 commit comments

Comments
 (0)