Skip to content
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

Improve event handler merging #1715

Merged
merged 2 commits into from Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/@headlessui-react/CHANGELOG.md
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ensure controlled `Tabs` don't change automagically ([#1680](https://github.com/tailwindlabs/headlessui/pull/1680))
- Don't scroll lock when a Transition + Dialog is mounted but hidden ([#1681](https://github.com/tailwindlabs/headlessui/pull/1681))
- Improve outside click on Safari iOS ([#1712](https://github.com/tailwindlabs/headlessui/pull/1712))
- Improve event handler merging ([#1715](https://github.com/tailwindlabs/headlessui/pull/1715))

## [1.6.6] - 2022-07-07

Expand Down
9 changes: 7 additions & 2 deletions packages/@headlessui-react/src/utils/render.ts
Expand Up @@ -232,11 +232,16 @@ function mergeProps(...listOfProps: Props<any, any>[]) {
// Merge event handlers
for (let eventName in eventHandlers) {
Object.assign(target, {
[eventName](event: { defaultPrevented: boolean }, ...args: any[]) {
[eventName](event: { nativeEvent?: Event; defaultPrevented: boolean }, ...args: any[]) {
let handlers = eventHandlers[eventName]

for (let handler of handlers) {
if (event.defaultPrevented) return
if (
(event instanceof Event || event?.nativeEvent instanceof Event) &&
event.defaultPrevented
) {
return
}

handler(event, ...args)
}
Expand Down
1 change: 1 addition & 0 deletions packages/@headlessui-vue/CHANGELOG.md
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Resync input when display value changes ([#1679](https://github.com/tailwindlabs/headlessui/pull/1679))
- Ensure controlled `Tabs` don't change automagically ([#1680](https://github.com/tailwindlabs/headlessui/pull/1680))
- Improve outside click on Safari iOS ([#1712](https://github.com/tailwindlabs/headlessui/pull/1712))
- Improve event handler merging ([#1715](https://github.com/tailwindlabs/headlessui/pull/1715))

## [1.6.7] - 2022-07-12

Expand Down
4 changes: 3 additions & 1 deletion packages/@headlessui-vue/src/utils/render.ts
Expand Up @@ -220,7 +220,9 @@ function mergeProps(...listOfProps: Record<any, any>[]) {
let handlers = eventHandlers[eventName]

for (let handler of handlers) {
if (event?.defaultPrevented) return
if (event instanceof Event && event.defaultPrevented) {
return
}

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