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

web: Remove deprecated input event listeners #861

Merged
merged 1 commit into from
Jul 7, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -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}") }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,49 +43,4 @@ class InputAttrsBuilder<T>(val inputType: InputType<T>) : AttrsBuilder<HTMLInput
listener(SyntheticInputEvent(value, it.nativeEvent.target as HTMLInputElement, 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))
}

@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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLTextAreaElement>() {
Expand All @@ -20,13 +20,4 @@ class TextAreaAttrsBuilder : AttrsBuilder<HTMLTextAreaElement>() {
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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -80,4 +80,4 @@ fun CodeSnippet(code: String, language: String = "kotlin") {
private fun HTMLElement.setHighlightedCode(code: String) {
innerText = code
HighlightJs.highlightElement(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ fun MyInputComponent(text: State<String>, 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()}")
Expand All @@ -283,8 +283,8 @@ fun MyInputComponent(text: State<String>, 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 = {
Expand All @@ -295,17 +295,17 @@ fun MyInputComponent(text: State<String>, onChange: (String) -> Unit) {
Input(
type = InputType.Radio,
attrs = {
onRadioInput {
println("Radio 1 - Checked: " + it.checked)
onInput {
println("Radio 1 - Checked: " + it.value)
}
name("f1")
}
)
Input(
type = InputType.Radio,
attrs = {
onRadioInput {
println("Radio 2 - Checked: " + it.checked)
onInput {
println("Radio 2 - Checked: " + it.value)
}
name("f1")
}
Expand Down
5 changes: 2 additions & 3 deletions web/widgets/src/jsMain/kotlin/layouts/slider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
)
Expand Down