Returns [InputTransformation] that rejects input which causes the total length of the text field to be more than [maxLength] characters.
BasicTextFieldInputTransformationMaxLengthCustom
@Composable
fun BasicTextFieldInputTransformationMaxLengthCustom() {
val state = remember { TextFieldState() }
BasicTextField(
state,
inputTransformation =
object : InputTransformation {
override fun SemanticsPropertyReceiver.applySemantics() {
maxLength(14)
}
override fun TextFieldBuffer.transformInput() {
if (length > 10) revertAllChanges()
}
},
outputTransformation =
OutputTransformation {
if (length > 0) insert(0, "(")
if (length > 4) insert(4, ") ")
if (length > 9) insert(9, "-")
},
)
}