kobaltedev / kobalte

A UI toolkit for building accessible web apps and design systems with SolidJS.
https://kobalte.dev
MIT License
1.2k stars 61 forks source link

How to make Anchor working with DropdownMenu.Item? #240

Closed izcream closed 9 months ago

izcream commented 1 year ago

Describe the bug I try to make a simple dropdown menu with <A> component on solid-start

my first try code is

<DropdownMenu.Item>
  <A href="/login">Login</A>
</DropdownMenu.Item>

with this code it will not navigate to /login

the second try

<DropdownMenu.Item asChild>
  <As
      component={A}
      href="/login>Login
  </As>
</DropdownMenu.Item>

its still not navigate to /login

only this way will navigate me to /login

<DropdownMenu.Item asChild onSelect={() => navigate('/login')}>
  <As
    component={A}
    href="/login">Login
  </As>
</DropdownMenu.Item>

how to make anchor link work normally without onSelect?

ps. sorry if my issue gone wrong

Additional context Add any other context about the problem here.

armandsalle commented 1 year ago

Hey 👋 I tried to recreate the issue but it works fine for me. Can you give more informations about what you want to achieve and more code please?

My test https://codesandbox.io/p/sandbox/cold-bash-hgltfl?file=%2Fsrc%2FApp.tsx%3A6%2C24

izcream commented 1 year ago

i have try with native anchor element(a) like you sandbox but still no luck about it. i have use solid-start not solid-vitejs(not sure bot are same or not) below is code image

both component="a" or component={A} will not navigate me to new url

only this way will navigate me to new url image

dependency version information

"@kobalte/core": "^0.9.8",
"@solidjs/router": "^0.8.2",
"solid-js": "^1.7.8",
"solid-start": "^0.2.29"
andrewrosss commented 11 months ago

It looks like closeOnSelect might have something to do with this issue.

Specifically, if you want to include a link as one of the dropdown menu items it seems like you can do this:

<DropdownMenu.Item asChild closeOnSelect={false}> // note: closeOnSelect={false}
  <As component={A} href={"/wherever"}>
    <DropdownMenu.ItemLabel>My link</DropdownMenu.ItemLabel>
  </As>
</DropdownMenu.Item>

Here's a link to a reproduction

Brian-Pob commented 11 months ago

I had a similar issue using Kobalte in an Astro project and @andrewrosss 's solution worked for me. Thanks.

syahzuan commented 9 months ago

Encountering the same issue using Kobalte in an Astro project. Solved with @andrewrosss 's solution. Many thanks, Andrew!

marioparaschiv commented 5 months ago

i have try with native anchor element(a) like you sandbox but still no luck about it. i have use solid-start not solid-vitejs(not sure bot are same or not) below is code image

both component="a" or component={A} will not navigate me to new url

only this way will navigate me to new url image

dependency version information

"@kobalte/core": "^0.9.8",
"@solidjs/router": "^0.8.2",
"solid-js": "^1.7.8",
"solid-start": "^0.2.29"

What font is this?