ui icon indicating copy to clipboard operation
ui copied to clipboard

Anchor tag hyperlink to page fragments not working on Drawer (Vaul)

Open subhranshudas opened this issue 1 year ago • 4 comments

Guys/Gals,

Following is my setup

  • Next JS - 14
  • UI lib - https://ui.shadcn.com/docs/components/drawer (from vaul)

I have a responsive navbar, on desktop sizes show the navlinks in the middle, and on smaller/mobile sizes show them on the drawer when clicked on the hamburger menu icon.

Now my navlinks when clicked takes the user to a fragment on the same page. ( with #fragmentID)

The issue I am facing is In the Mobile Nav Drawer, I am wrapping the "a" tag with DrawerClose to trigger a close. When i click on a link the Drawer closes but the hyperlink section is not getting scrolled to.

I feel the hyperlink click event is somehow getting hijacked by Vaul Drawer. This issue doesn't happen in https://ui.shadcn.com/docs/components/sheet

Any help is appreciated!

Regards.

subhranshudas avatar Feb 22 '24 11:02 subhranshudas

I have the same problem here. I tried working around this by programmatically closing the drawer (open and onOpenChange in the drawer), and navigating to the id by selecting the element (getElementById) and scroll to it with .scrollIntoView(), but no dice, it just won't work.

I see that the url gets set correctly, it just won't scroll. I guess the drawer overlays itself on everything, and the id's can't be found below it.

I guess I'm also switching to the sheet then. Thanks for the tipp.

KyrillGobber avatar Feb 28 '24 16:02 KyrillGobber

Well, setTimout(element.scrollIntoView(), 350) after closing the drawer works of course. But that's an ugly workaround.

KyrillGobber avatar Feb 28 '24 16:02 KyrillGobber

Hey @KyrillGobber i am yet to try out the setTimeout with scrollIntoView, but yes you are right thats an ugly hack. Will update this thread if i find something more concise. Thanks!

subhranshudas avatar Mar 03 '24 14:03 subhranshudas

I have the same issue, any updates?

AuJezus avatar May 14 '24 18:05 AuJezus

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Jun 10 '24 23:06 shadcn