KTextField - farimarwat/KrossUi GitHub Wiki

✏️ KTextField Component Documentation

A simple and customizable cross-platform text field component for Kotlin Multiplatform projects.


🔹 Overview

Element Type Description
KTextField Composable Renders a cross-platform text input field.
KTextFieldColors Data Class Holds color settings for the text field.
KTextFieldDefaults Object Provides default color configurations.

🧩 KTextField

Definition:
A composable text input field that adapts to both Android and iOS, with styling and placeholder support.

Parameters

Parameter Type Description
modifier Modifier Modifier to style layout.
value String Current text input value.
onValueChange (String) -> Unit Callback for handling text changes.
placeholder String Placeholder text when input is empty.
colors KTextFieldColors Color configuration for background, text, and border.

🎨 KTextFieldColors

Defines the visual appearance of the text field component.

Properties

Property Type Description
background Color Background color of the text field.
textColor Color Color of the input text.
placeholderColor Color Color of the placeholder text.
borderColor Color Border color of the text field.

⚙️ KTextFieldDefaults

Provides a helper to create color configurations easily.

🎛️ colors(...)

Returns a KTextFieldColors instance with optional custom overrides.

Parameter Type Default Value Description
background Color Theme based Text field background color.
textColor Color Theme based Text color.
placeholderColor Color Gray Color of the placeholder text.
borderColor Color Light gray Border color.

✅ Usage Example

var textValue by remember { mutableStateOf("") }

KTextField(
    modifier = Modifier.fillMaxWidth(),
    value = textValue,
    onValueChange = {
        textValue = it
        println("Input: $it")
    },
    cornerRadius = 8.0,
    borderWidth = 1,
    padding = KPadding.horizontal(12.0),
    colors = KTextFieldDefaults.colors(
        focusedBackgroundColor = Color.LightGray
    )
)

🔹 Note:

  • value holds the current input text.
  • onValueChange updates as the user types.
  • cornerRadius, borderWidth, and padding allow full customization.
  • Use KTextFieldDefaults.colors(...) to style focus/background.
  • Adapts to native input styles on Android and iOS.