Raxol.UI.Components.TextInput (Raxol v0.5.0)
View SourceA text input component with editing capabilities.
This module provides a text input field that allows users to enter and edit text with cursor positioning, selection, and validation.
Example
alias Raxol.UI.Components.TextInput
TextInput.new(
value: model.name,
placeholder: "Enter your name",
on_change: fn value -> {:update_name, value} end
)
Summary
Functions
Updates the text input based on keyboard input.
Creates a new text input with the given options.
Renders the text input as a basic element.
Types
@type t() :: map()
Functions
Updates the text input based on keyboard input.
Parameters
input
- The text input componentkey_event
- Keyboard event as{meta, key}
Returns
Updated text input component.
Example
updated_input = TextInput.handle_key_event(input, {:none, ?a})
Creates a new text input with the given options.
Options
:value
- Current input value:placeholder
- Placeholder text when empty:on_change
- Function to call when value changes:password
- Whether to mask input as password:max_length
- Maximum input length:style
- Custom style for the input:disabled
- Whether the input is disabled:validation
- Validation function:invalid_message
- Message to show when validation fails
Returns
A text input component that can be used in a Raxol view.
Example
TextInput.new(
value: model.email,
placeholder: "example@example.com",
validation: &String.contains?(&1, "@"),
invalid_message: "Must be a valid email"
)
Renders the text input as a basic element.
This is typically called by the renderer, not directly by users.