diff --git a/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/Attrs.kt b/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/Attrs.kt index 9510514594..0b46009039 100644 --- a/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/Attrs.kt +++ b/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/Attrs.kt @@ -211,7 +211,7 @@ fun AttrsBuilder.label(value: String) = /* Select attributes */ -fun AttrsBuilder.autocomplete(value: AutoComplete) = +fun AttrsBuilder.autoComplete(value: AutoComplete) = attr("autocomplete", value.unsafeCast()) fun AttrsBuilder.autofocus() = diff --git a/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/PredefinedAttrValues.kt b/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/PredefinedAttrValues.kt index 1c9638bbe0..56565090b7 100644 --- a/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/PredefinedAttrValues.kt +++ b/web/core/src/jsMain/kotlin/androidx/compose/web/attributes/PredefinedAttrValues.kt @@ -1,5 +1,3 @@ -@file:Suppress("Unused", "NOTHING_TO_INLINE", "NESTED_CLASS_IN_EXTERNAL_INTERFACE", "INLINE_EXTERNAL_DECLARATION", "WRONG_BODY_OF_EXTERNAL_DECLARATION", "NESTED_EXTERNAL_DECLARATION", "ClassName") - package org.jetbrains.compose.web.attributes import org.w3c.dom.events.Event @@ -168,6 +166,7 @@ enum class Scope(val str: String) { /** * https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete */ +@Suppress("Unused", "NOTHING_TO_INLINE", "NESTED_CLASS_IN_EXTERNAL_INTERFACE", "INLINE_EXTERNAL_DECLARATION", "WRONG_BODY_OF_EXTERNAL_DECLARATION", "NESTED_EXTERNAL_DECLARATION", "ClassName") external interface AutoComplete { external companion object { /** @@ -184,7 +183,7 @@ external interface AutoComplete { /** *The field expects the value to be a person's full name. Using "name" rather than breaking the name down into its components is generally preferred because it avoids dealing with the wide diversity of human names and how they are structured; however, you can use the following autocomplete values if you do need to break the name down into its components: */ - inline val Name get() = AutoComplete("name") + inline val name get() = AutoComplete("name") /** * The prefix or title, such as "Mrs.", "Mr.", "Miss", "Ms.", "Dr.", or "Mlle.". @@ -436,4 +435,5 @@ external interface AutoComplete { } } +@Suppress("NOTHING_TO_INLINE") inline fun AutoComplete(value: String) = value.unsafeCast() diff --git a/web/core/src/jsTest/kotlin/elements/InputsGenerateCorrectHtmlTests.kt b/web/core/src/jsTest/kotlin/elements/InputsGenerateCorrectHtmlTests.kt index 69d674b5eb..b268e52fd8 100644 --- a/web/core/src/jsTest/kotlin/elements/InputsGenerateCorrectHtmlTests.kt +++ b/web/core/src/jsTest/kotlin/elements/InputsGenerateCorrectHtmlTests.kt @@ -1,5 +1,8 @@ package org.jetbrains.compose.web.core.tests.elements +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.compose.runtime.getValue import org.jetbrains.compose.web.attributes.* import org.jetbrains.compose.web.core.tests.runTest import org.jetbrains.compose.web.dom.* @@ -391,9 +394,47 @@ class InputsGenerateCorrectHtmlTests { fun textInputWithAutoComplete() = runTest { composition { TextInput { - autoComplete(AutoComplete.Name) + autoComplete(AutoComplete.name) } } assertEquals("""""", root.innerHTML) } + + @Test + fun textAreaWithAutoComplete() = runTest { + composition { + TextArea({ + autoComplete(AutoComplete.email) + }, value = "") + } + assertEquals("""""", root.innerHTML) + } + + @Test + fun formWithAutoComplete() = runTest { + var autoCompleteEnabled by mutableStateOf(true) + + composition { + Form(attrs = { + autoComplete(autoCompleteEnabled) + }) + } + + assertEquals("""
""", root.innerHTML) + + autoCompleteEnabled = false + waitChanges() + + assertEquals("""
""", root.innerHTML) + } + + @Test + fun selectWithAutoComplete() = runTest { + composition { + Select({ + autoComplete(AutoComplete.tel) + }) + } + assertEquals("""""", root.innerHTML) + } }