nextui icon indicating copy to clipboard operation
nextui copied to clipboard

[BUG] - Button press event should not propagate to parent Link.

Open chen-yan opened this issue 10 months ago • 3 comments

HeroUI Version

2.6, 2.7

Describe the bug

When click a Button inside Link component (ListboxItem and some other components has href attribute will render as link) should not causing page redirect by Link.

We can stop it by adding onClick (e=>{e.preventDefault()}), but I think it should be work as default as PressEvent's shouldStopPropagation is true and onClick method is marked as deprecated.

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

code example:

<Link href="/other-page"> <span>Other Page</span> <Button onPress={console.log("button clicked.")}>button</Button> </Link>

when button clicked, page jump to "other-page"

Expected behavior

stay on current page, print log.

Screenshots or Videos

No response

Operating System Version

Windows, MacOS

Browser

Safari

chen-yan avatar Feb 20 '25 02:02 chen-yan

I'd like to work on this

leotaozeng avatar Feb 21 '25 09:02 leotaozeng

I believe this is not a HeroUI issue rather than React Aria.

First of all, button shouldn't be nested inside a, it's not valid HTML. See here https://github.com/adobe/react-spectrum/issues/963#issuecomment-674176254.

Also according to this comment, the current solution is to use onClick={e => e.preventDefault()}.

leotaozeng avatar Feb 22 '25 09:02 leotaozeng