Skip to content

Commit

Permalink
Fix event handlers with arity > 1 (#1515)
Browse files Browse the repository at this point in the history
* fix event handlers with arity > 1

* update changelog
  • Loading branch information
RobinMalfait committed May 28, 2022
1 parent a7154dc commit 21bdf52
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Ensure `Escape` propagates correctly in `Combobox` component ([#1511](https://github.com/tailwindlabs/headlessui/pull/1511))
- Remove leftover code in Combobox component ([#1514](https://github.com/tailwindlabs/headlessui/pull/1514))
- Fix event handlers with arity > 1 ([#1515](https://github.com/tailwindlabs/headlessui/pull/1515))

## [Unreleased - @headlessui/vue]

Expand Down
6 changes: 3 additions & 3 deletions packages/@headlessui-react/src/utils/render.ts
Expand Up @@ -201,7 +201,7 @@ function mergeProps(...listOfProps: Props<any, any>[]) {

let eventHandlers: Record<
string,
((event: { defaultPrevented: boolean }) => void | undefined)[]
((event: { defaultPrevented: boolean }, ...args: any[]) => void | undefined)[]
> = {}

for (let props of listOfProps) {
Expand Down Expand Up @@ -232,13 +232,13 @@ function mergeProps(...listOfProps: Props<any, any>[]) {
// Merge event handlers
for (let eventName in eventHandlers) {
Object.assign(target, {
[eventName](event: { defaultPrevented: boolean }) {
[eventName](event: { defaultPrevented: boolean }, ...args: any[]) {
let handlers = eventHandlers[eventName]

for (let handler of handlers) {
if (event.defaultPrevented) return

handler(event)
handler(event, ...args)
}
},
})
Expand Down

0 comments on commit 21bdf52

Please sign in to comment.