-
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: restore position settings on drawer unmount (#462)
* fix: restore position settings on drawer destroy * fix: typo * fix: unused att
- Loading branch information
1 parent
995e36a
commit 1142f66
Showing
5 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use client'; | ||
|
||
export default function Page() { | ||
return ( | ||
<div className="bg-zinc-100 space-y-10"> | ||
<p className="pb-[120vh] bg-zinc-600 text-white font-bold">scroll down</p> | ||
<p data-testid="content" className="py-32 bg-zinc-800 text-white">content only visible after scroll</p> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use client'; | ||
|
||
import Link from 'next/link'; | ||
import { Drawer } from 'vaul'; | ||
|
||
export default function Page() { | ||
return ( | ||
<div className="w-screen h-screen bg-white p-8 flex justify-center items-center"> | ||
<Drawer.Root> | ||
<Drawer.Trigger asChild> | ||
<button data-testid="trigger" className="text-2xl"> | ||
Open Drawer | ||
</button> | ||
</Drawer.Trigger> | ||
<Drawer.Portal> | ||
<Drawer.Overlay data-testid="overlay" className="fixed inset-0 bg-black/40" /> | ||
<Drawer.Content | ||
data-testid="content" | ||
className="bg-zinc-100 flex flex-col rounded-t-[10px] h-[96%] mt-24 fixed bottom-0 left-0 right-0" | ||
> | ||
<Drawer.Close data-testid="drawer-close">Close</Drawer.Close> | ||
<div className="p-4 bg-white rounded-t-[10px] flex-1"> | ||
<div className="mx-auto w-12 h-1.5 flex-shrink-0 rounded-full bg-zinc-300 mb-8" /> | ||
<div className="max-w-md mx-auto"> | ||
<Drawer.Title className="font-medium mb-4">Redirect to another route.</Drawer.Title> | ||
<p className="text-zinc-600 mb-2">This route is only used to test the body reset position.</p> | ||
<p className="text-zinc-600 mb-8"> | ||
Go to{' '} | ||
<Link href="/with-redirect/long-page" data-testid="link" className="underline"> | ||
another route | ||
</Link>{' '} | ||
</p> | ||
</div> | ||
</div> | ||
</Drawer.Content> | ||
</Drawer.Portal> | ||
</Drawer.Root> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { openDrawer } from './helpers'; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/with-redirect'); | ||
}); | ||
|
||
test.describe('With redirect', () => { | ||
test('should restore body position settings', async ({ page }) => { | ||
await openDrawer(page); | ||
await page.getByTestId('link').click(); | ||
|
||
await page.waitForURL('**/with-redirect/long-page'); | ||
|
||
const content = page.getByTestId('content'); | ||
|
||
// safe check | ||
await expect(content).toBeVisible(); | ||
|
||
content.scrollIntoViewIfNeeded(); | ||
|
||
await expect(page.getByTestId('content')).toBeInViewport(); | ||
}); | ||
}); |