From 21bdf529de64ca6b4459b0a9035d6cfee6325b11 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Sat, 28 May 2022 17:32:00 +0200 Subject: [PATCH] Fix event handlers with arity > 1 (#1515) * fix event handlers with arity > 1 * update changelog --- CHANGELOG.md | 1 + packages/@headlessui-react/src/utils/render.ts | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb66a43a45..324dac7569 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/packages/@headlessui-react/src/utils/render.ts b/packages/@headlessui-react/src/utils/render.ts index 36369eae94..7b949d82cb 100644 --- a/packages/@headlessui-react/src/utils/render.ts +++ b/packages/@headlessui-react/src/utils/render.ts @@ -201,7 +201,7 @@ function mergeProps(...listOfProps: Props[]) { 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[]) { // 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) } }, })