Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll back to top on drawer closed #72

Open
PierroCesi opened this issue Nov 26, 2024 · 3 comments
Open

Scroll back to top on drawer closed #72

PierroCesi opened this issue Nov 26, 2024 · 3 comments

Comments

@PierroCesi
Copy link

Video

Screen.Recording.2024-11-26.at.16.16.21.mov

Bug Description

When using Vaul Drawer in a Vue/Nuxt application with shadcn-ui, the page automatically scrolls to the top even when the Drawer is not displayed.

Steps to Reproduce

  1. Have a page with nested components
  2. One of these components includes a Drawer (even if not visible)
  3. Navigate to this page
  4. The page automatically scrolls to the top

Expected Behavior

The page should maintain its scroll position when navigating to a component that contains a Drawer.

Current Behavior

The page automatically scrolls to the top when mounting a component containing a Drawer, even if the Drawer is not visible/active.

Additional Context

  • Adding :preventScrollRestoration="true" to the Drawer component doesn't solve the issue
  • This happens specifically when the Drawer is nested in other components
  • The scroll behavior occurs on component mount, not on Drawer interaction

Environment

  • Vue.js version: 3.3.4
  • Vaul-vue version: 0.2.0
  • Radix Vue version: 1.9.1
  • Browser: Arc browser

Similar bug on React Drawer

@drefrajo
Copy link

Have you tried adding :nested="true" to the Drawer component?

@Hakim-Latroch
Copy link

This worked for me :

<DrawerContent onCloseAutoFocus={(e) => e.preventDefault()}> ..</DrawerContent>

Prevent Default Focus Behavior:
Issue: Some drawer components may focus on a specific element upon closing, causing the page to scroll.
Solution: Prevent the default focus behavior when the drawer closes.

@Ishidall
Copy link

Ishidall commented Feb 4, 2025

@Hakim-Latroch

<DrawerContent onCloseAutoFocus={(e) => e.preventDefault()}> ..</DrawerContent>

This fixed my problem on Mac(Intel)'s Chrome, Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants