[Bug]: Popover.Button is clobbering the `onClick` prop
See original GitHub issueWhat package within Headless UI are you using?
What version of that package are you using?
v1.4.1
What browser are you using?
Chrome, Firefox, etc.
Reproduction repository
Describe your issue
Looking at the source, it seems Popover.Button
is clobbering any existing onClick
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 the event.clientX
, as shown by Popper JS’s author here.
I believe calling any existing onClick
prop at the top on handleClick
, with the current event, would address this problem.
Thank you
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:7
Top Results From Across the Web
ReactJS - popover onClick insde data-content doesn't work
I'm using a button and inside I have an Icon and when click should popover its data-content, and it does! but the onClick...
Read more >HeadlessUI: Popover. Part 3 - JavaScript in Plain English
Part 2: Styling an open panel's button — In this part, we are going to add the Chevron right icon at the Popover...
Read more >LineChart chart/line
Renders a button and calls the given `onClick` function, if given, when clicked. Any children passed will be redirected inside the button. Passing...
Read more >Ext.tip.ToolTip | Ext JS 7.3.1 - Sencha Documentation
This object holds a map of config properties that will update their binding as they are modified. For example, value is a key...
Read more >Auto Draft - IndustrialSage
getSnapshotBeforeUpdate(p,m)),C=null!=c&&c.type===y&&null==c.key?c.props. ... fireEvent("on"+t,a)}u.wlog.error("neither dispatchEvent nor fireEvent is ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
Hey! Thank you for your bug report! Much appreciated! 🙏
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
onClick
,onKeyDown
, … even if we also provide those. Your handlers will be executed before ours which gives you an opportunity to do anything to theevent
(evenevent.preventDefault()
) if you would like to for whatever reason.You can already try it using
npm install @headlessui/react@insiders
oryarn add @headlessui/react@insiders
.