Fix event handlers with arity > 1 (#1515)

* fix event handlers with arity > 1

* update changelog
This commit is contained in:
Robin Malfait
2022-05-28 17:32:00 +02:00
committed by GitHub
parent a7154dca1f
commit 21bdf529de
2 changed files with 4 additions and 3 deletions
+1
View File
@@ -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]
@@ -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) {
@@ -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)
}
},
})