You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PopoverButton takes an as prop which can be a custom component but presumably event.preventDefault() is called within the click handler, preventing any default behaviour that you may have, e.g. if you want to render a link instead of a button:
You can do <PopoverButton as="div"> but that's not right either, since for accessibility reasons you should not have a clickable div.
Okay, so then maybe PopoverButton insists that, because it's a clickable trigger, it must be a button - it's in the name, right? So then there should be no as prop at all?
If you want to have anything other than a button as your popover trigger, you're at a bit of an impasse.
Seems like there should be an imperative way to toggle the popover's state.
Link is one example but there very well could be cases that we cannot foresee. Behaviour like this should be left unrestricted, for the implementer to decide.
The text was updated successfully, but these errors were encountered:
Just figured this out. Still kind of an issue though.
If in your custom component which you pass in as={Component} you have a click event handler, anything at all, then the event is not prevented, and the default browser behaviour proceeds, i.e.:
constMyPopoverButton=()=>{return<PopoverButtonas={MyLinkComponent}href="/">...</PopoverButton>;};constMyLinkComponent=forwardRef(({ children, ...props},ref)=>{return(<a{...props}ref={ref}onClick={()=>{}}// <-- THIS GUY RIGHT HERE>{children}</a>);});
Happy to have figured out a workaround for now, and I get why it would have been done this way, but still, this is rather bizarre.
sstackus
changed the title
PopoverButton hogs the event - cannot freely use its as propPopoverButton hogs the event - cannot use as prop with LinkNov 18, 2024
What package within Headless UI are you using?
@headlessui/react
What version of that package are you using?
v2.2.0
What browser are you using?
Firefox
Reproduction URL
https://codesandbox.io/p/devbox/morning-sea-9zfs2r
Describe your issue
PopoverButton
takes anas
prop which can be a custom component but presumablyevent.preventDefault()
is called within the click handler, preventing any default behaviour that you may have, e.g. if you want to render a link instead of a button:The logical next solution is to then just avoid
as
and render my custom component as a child:However, this results in:
which is obviously not right.
You can do
<PopoverButton as="div">
but that's not right either, since for accessibility reasons you should not have a clickablediv
.Okay, so then maybe
PopoverButton
insists that, because it's a clickable trigger, it must be a button - it's in the name, right? So then there should be noas
prop at all?If you want to have anything other than a button as your popover trigger, you're at a bit of an impasse.
Seems like there should be an imperative way to toggle the popover's state.
Link is one example but there very well could be cases that we cannot foresee. Behaviour like this should be left unrestricted, for the implementer to decide.
The text was updated successfully, but these errors were encountered: