TextField Widget
This content is for v1.1.2. Switch to the latest version for up-to-date documentation.
TextField provides native Android text input with support for standard keyboard types, placeholder hints, secure password masking, and robust text selection.
Code Example
Section titled “Code Example”from zkite import Column, TextField, Text
def LoginForm(store): return Column( "gap-3 w-full", Text("text-sm font-medium text-slate-300", "Email Address"), TextField( "p-3 bg-slate-900 border border-slate-700 rounded-lg text-white", value=store.email, placeholder="name@example.com", type="email", on_change=lambda text: store.update(email=text), ), Text("text-sm font-medium text-slate-300", "Password"), TextField( "p-3 bg-slate-900 border border-slate-700 rounded-lg text-white", value=store.password, placeholder="••••••••", secure=True, on_change=lambda text: store.update(password=text), ), )Constructor & Properties
Section titled “Constructor & Properties”TextField( classes: str, value: str = "", placeholder: str = "", type: str = "text", secure: bool = False, on_change = None, on_input = None, key: str | None = None)| Parameter | Type | Default | Description |
|---|---|---|---|
classes |
str |
None | Styling classes for padding, background, borders, and text typography. |
value |
str |
"" |
The current controlled string value displayed in the field. |
placeholder |
str |
"" |
Light hint text shown when value is empty. |
type |
str |
"text" |
Software keyboard hint: "text", "email", "url", "tel", or "number". |
secure |
bool |
False |
When True, obscures text input with password masking. |
on_change |
Callable[[str], None] |
None |
Callback invoked with the updated text when editing commits. |
on_input |
Callable[[str], None] |
None |
Callback invoked immediately on every single keystroke. |
key |
str |
None |
Stable identity key. |
Controlled State & Event Timing
Section titled “Controlled State & Event Timing”on_inputvson_change: On the native backend, text-change callbacks follow editing. Useon_inputfor immediate per-keystroke responsiveness (e.g. search filtering); useon_changefor committed form values.- Controlled Value Pattern: Always write the updated text back to your store. If your callback does not update the store field, a subsequent render can revert the displayed text.
Keyboard Testing & Text Selection Stability
Section titled “Keyboard Testing & Text Selection Stability”When testing text input, verify on physical Android hardware:
- Deleting all text until empty.
- Inserting characters in the middle of existing text.
- Selecting a range of text, copying, and pasting using the native selection toolbar.
- Inputting multi-byte Unicode characters and emojis.
- Dismissing the soft keyboard and returning from other apps.
- Preserve Field Keys: Always preserve the field’s
keyso ordinary state updates do not recreate the field and dismiss the keyboard unexpectedly.
