From 8edc12f02aa387b31a4c1366281e203731b38ed5 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpovich Date: Wed, 7 Jul 2021 12:16:38 +0200 Subject: [PATCH] web: Remove deprecated input event listeners (#861) Co-authored-by: Oleksandr Karpovich --- .../com/sample/content/CodeSamplesSwitcher.kt | 2 +- .../web/attributes/InputAttrsBuilder.kt | 53 ++----------------- .../web/attributes/TextAreaAttrsBuilder.kt | 13 +---- .../compose/web/sample/CodeSnippetSamples.kt | 6 +-- .../androidx/compose/web/sample/Sample.kt | 16 +++--- .../src/jsMain/kotlin/layouts/slider.kt | 5 +- 6 files changed, 19 insertions(+), 76 deletions(-) diff --git a/web/benchmark-core/src/jsMain/kotlin/com/sample/content/CodeSamplesSwitcher.kt b/web/benchmark-core/src/jsMain/kotlin/com/sample/content/CodeSamplesSwitcher.kt index 30fe58fd9a..6d6e300cd6 100644 --- a/web/benchmark-core/src/jsMain/kotlin/com/sample/content/CodeSamplesSwitcher.kt +++ b/web/benchmark-core/src/jsMain/kotlin/com/sample/content/CodeSamplesSwitcher.kt @@ -75,7 +75,7 @@ fun CodeSampleSwitcher(count: Int, current: Int, onSelect: (Int) -> Unit) { value("snippet$ix") id("snippet$ix") if (current == ix) checked() - onRadioInput { onSelect(ix) } + onInput { onSelect(ix) } }) Label(forId = "snippet$ix") { Text("${ix + 1}") } } diff --git a/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/InputAttrsBuilder.kt b/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/InputAttrsBuilder.kt index 4d96b08a30..37e0b438b2 100644 --- a/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/InputAttrsBuilder.kt +++ b/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/InputAttrsBuilder.kt @@ -5,11 +5,9 @@ package androidx.compose.web.attributes -import org.jetbrains.compose.web.attributes.* -import org.jetbrains.compose.web.events.GenericWrappedEvent -import org.jetbrains.compose.web.events.WrappedCheckBoxInputEvent -import org.jetbrains.compose.web.events.WrappedRadioInputEvent -import org.jetbrains.compose.web.events.WrappedTextInputEvent +import org.jetbrains.compose.web.attributes.AttrsBuilder +import org.jetbrains.compose.web.attributes.InputType +import org.jetbrains.compose.web.attributes.Options import org.w3c.dom.HTMLElement import org.w3c.dom.HTMLInputElement import org.w3c.dom.events.Event @@ -45,49 +43,4 @@ class InputAttrsBuilder(val inputType: InputType) : AttrsBuilder Unit) { - listeners.add(TextInputEventListener(options, listener)) - } - - @Deprecated( - message = "It's not reliable as it can be applied to any input type.", - replaceWith = ReplaceWith("onInput(options, listener)"), - level = DeprecationLevel.WARNING - ) - fun onCheckboxInput( - options: Options = Options.DEFAULT, - listener: (WrappedCheckBoxInputEvent) -> Unit - ) { - listeners.add(CheckBoxInputEventListener(options, listener)) - } - - @Deprecated( - message = "It's not reliable as it can be applied to any input type.", - replaceWith = ReplaceWith("onInput(options, listener)"), - level = DeprecationLevel.WARNING - ) - fun onRadioInput( - options: Options = Options.DEFAULT, - listener: (WrappedRadioInputEvent) -> Unit - ) { - listeners.add(RadioInputEventListener(options, listener)) - } - - @Deprecated( - message = "It's not reliable as it can be applied to any input type.", - replaceWith = ReplaceWith("onInput(options, listener)"), - level = DeprecationLevel.WARNING - ) - fun onRangeInput( - options: Options = Options.DEFAULT, - listener: (GenericWrappedEvent<*>) -> Unit - ) { - listeners.add(WrappedEventListener(INPUT, options, listener)) - } } diff --git a/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/TextAreaAttrsBuilder.kt b/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/TextAreaAttrsBuilder.kt index 9231233a18..223230ccc9 100644 --- a/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/TextAreaAttrsBuilder.kt +++ b/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/TextAreaAttrsBuilder.kt @@ -5,8 +5,8 @@ package androidx.compose.web.attributes -import org.jetbrains.compose.web.attributes.* -import org.jetbrains.compose.web.events.WrappedTextInputEvent +import org.jetbrains.compose.web.attributes.AttrsBuilder +import org.jetbrains.compose.web.attributes.Options import org.w3c.dom.HTMLTextAreaElement class TextAreaAttrsBuilder : AttrsBuilder() { @@ -20,13 +20,4 @@ class TextAreaAttrsBuilder : AttrsBuilder() { listener(SyntheticInputEvent(text, it.nativeEvent.target as HTMLTextAreaElement, it.nativeEvent)) } } - - @Deprecated( - message = "It's not reliable as it can be applied to any input type.", - replaceWith = ReplaceWith("onInput(options, listener)"), - level = DeprecationLevel.WARNING - ) - fun onTextInput(options: Options = Options.DEFAULT, listener: (WrappedTextInputEvent) -> Unit) { - listeners.add(TextInputEventListener(options, listener)) - } } diff --git a/web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/CodeSnippetSamples.kt b/web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/CodeSnippetSamples.kt index aed45eb50b..01e6607649 100644 --- a/web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/CodeSnippetSamples.kt +++ b/web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/CodeSnippetSamples.kt @@ -33,7 +33,7 @@ fun KotlinCodeSnippets() { type = InputType.Radio, attrs = { name("code-snippet") - onRadioInput { + onInput { currentSnippet.value = """ /* Adds two integers */ fun add(i: Int, j: Int): Int { @@ -47,7 +47,7 @@ fun KotlinCodeSnippets() { type = InputType.Radio, attrs = { name("code-snippet") - onRadioInput { + onInput { currentSnippet.value = """ /* Does some calculations */ fun calculate(i: Int, j: Int): Int { @@ -80,4 +80,4 @@ fun CodeSnippet(code: String, language: String = "kotlin") { private fun HTMLElement.setHighlightedCode(code: String) { innerText = code HighlightJs.highlightElement(this) -} \ No newline at end of file +} diff --git a/web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/Sample.kt b/web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/Sample.kt index 4aaee219a8..3cc752def6 100644 --- a/web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/Sample.kt +++ b/web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/Sample.kt @@ -272,8 +272,8 @@ fun MyInputComponent(text: State, onChange: (String) -> Unit) { onKeyDown { println("On keyDown key = : ${it.getNormalizedKey()}") } - onTextInput { - onChange(it.inputValue) + onInput { + onChange(it.value) } onKeyUp { println("On keyUp key = : ${it.getNormalizedKey()}") @@ -283,8 +283,8 @@ fun MyInputComponent(text: State, onChange: (String) -> Unit) { } Div { Input(type = InputType.Checkbox, attrs = { - onCheckboxInput { - println("From div - Checked: " + it.checked) + onInput { + println("From div - Checked: " + it.value) } }) Input(type = InputType.Text, attrs = { @@ -295,8 +295,8 @@ fun MyInputComponent(text: State, onChange: (String) -> Unit) { Input( type = InputType.Radio, attrs = { - onRadioInput { - println("Radio 1 - Checked: " + it.checked) + onInput { + println("Radio 1 - Checked: " + it.value) } name("f1") } @@ -304,8 +304,8 @@ fun MyInputComponent(text: State, onChange: (String) -> Unit) { Input( type = InputType.Radio, attrs = { - onRadioInput { - println("Radio 2 - Checked: " + it.checked) + onInput { + println("Radio 2 - Checked: " + it.value) } name("f1") } diff --git a/web/widgets/src/jsMain/kotlin/layouts/slider.kt b/web/widgets/src/jsMain/kotlin/layouts/slider.kt index ed0f194469..396628c7fd 100644 --- a/web/widgets/src/jsMain/kotlin/layouts/slider.kt +++ b/web/widgets/src/jsMain/kotlin/layouts/slider.kt @@ -24,9 +24,8 @@ actual fun SliderActual( attr("min", valueRange.start.toString()) attr("max", valueRange.endInclusive.toString()) attr("step", step.toString()) - onRangeInput { - val value: String = it.nativeEvent.target.asDynamic().value - onValueChange(value.toFloat()) + onInput { + onValueChange(it.value?.toFloat() ?: 0f) } } )