From b20fd4d55d8ce9724370d57f68b6d883423ea908 Mon Sep 17 00:00:00 2001 From: Christian Hausknecht Date: Fri, 31 Jan 2025 13:42:35 +0100 Subject: [PATCH] Fixes a small potential bug on headless switch component (#933) The `click`-event is now correctly handled by stop propagating it and `preventDefault` as the headless component will do all the work. This could have led to bugs when using the component with explicit `DataBinging`, where the `handler`-lambda would be used to intercept the update call. Co-authored-by: christian.hausknecht --- .../jsMain/kotlin/dev/fritz2/headless/components/Switch.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/headless/src/jsMain/kotlin/dev/fritz2/headless/components/Switch.kt b/headless/src/jsMain/kotlin/dev/fritz2/headless/components/Switch.kt index 13a7be9b3..1d565f6d7 100644 --- a/headless/src/jsMain/kotlin/dev/fritz2/headless/components/Switch.kt +++ b/headless/src/jsMain/kotlin/dev/fritz2/headless/components/Switch.kt @@ -35,7 +35,10 @@ abstract class AbstractSwitch( attr(Aria.checked, enabled.asString()) attr(Aria.invalid, "true".whenever(value.hasError)) attr("tabindex", "0") - value.handler?.invoke(this, clicks.map { !value.data.first() }) + value.handler?.invoke(this, clicks { + stopImmediatePropagation() + preventDefault() + }.map { !value.data.first() }) value.handler?.invoke( this, keydownsIf {