-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Bug]: Popover.Button is clobbering the onClick
prop
#846
Comments
Any updates on this? I want to add an |
I'm using Helmet and personally achieved this adding this in
In case it helps. 🙂 |
@kloh-fr Thanks for the hint. I just tried it using How does your code work? Should you add the class to the wrapping body element? Wouldn't that create an empty body element? Edit: I figured out a way to do it. I have a
|
I need to open a modal right after closing the popover. The |
This has come up for me when integrating with nextjs's navigation.map((item) =>{
return (
<Disclosure.Button as={Fragment} key={item.name}>
<Link href={item.href} >
<a>{item.name}</a>
</Link>
</Disclosure.Button>
);
} However, that results in "Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()" Next I tried moving navigation.map((item) =>{
return (
<Link href={item.href} key={item.name} >
<Disclosure.Button as={Fragment} >
<a>{item.name}</a>
</Disclosure.Button>
</Link>
);
} Then I tried using I got rid of the I think the issue is that both I did finally get it to sort of work by inserting a navigation.map((item) =>{
return (
<Disclosure.Button as={Fragment} key={item.name}>
<div className="px-4 py-4 text-base text-gray-500">
<Link href={item.href}>
<a className="block">{item.name}</a>
</Link>
</div>
</Disclosure.Button>
);
} |
I'm having a similar issue – I need to save user selections on the Popover to a global state object before closing. This hack appears to work for me: <div onClick={() => {
console.log('#onclick')
doSomething() // save states or do something imperatively
}}>
<Popover.Button>Apply</Popover.Button>
</div> |
Hey! Thank you for your bug report! This should be fixed by #1265, and will be available in the next release. The PR allows you to write your own event handlers like You can already try it using |
What package within Headless UI are you using?
@headlessui/react
What version of that package are you using?
v1.4.1
What browser are you using?
Chrome, Firefox, etc.
Reproduction repository
https://github.com/tailwindlabs/headlessui/blob/main/packages/%40headlessui-react/src/components/popover/popover.tsx#L475
Describe your issue
Looking at the source, it seems
Popover.Button
is clobbering any existingonClick
prop on the button.This prevents any code to be run before the Popover.Button's own
handleClick
logic.Such code would be useful to override the Popper JS positioning logic dynamically before the popper itself is displayed, something that can't always be done with the static options passed to
usePopper()
. For example, I'm trying to position the popper horizontally with respect to theevent.clientX
, as shown by Popper JS's author here.I believe calling any existing
onClick
prop at the top onhandleClick
, with the current event, would address this problem.Thank you
The text was updated successfully, but these errors were encountered: