TextField

TextField is a high-level text entry component that provides native styles and behaviors out of the box. Unlike the low-level TextInput, which is a bare primitive, TextField follows platform-specific design guidelines (such as Material 3 on Android) and includes built-in styling for focus states, labels, and containers.

Basic Usage

TextField can be used as a controlled or uncontrolled component. For controlled usage, you can pass a standard Solid signal or use the TextFieldRef for imperative control.

import { createSignal } from "solid-js";
import { TextField, View } from "@zynthjs/components";

function LoginScreen() {
  const [email, setEmail] = createSignal("");

  return (
    <View style={{ padding: 20 }}>
      <TextField
        value={email()}
        onChange={setEmail}
        placeholder="Email Address"
        keyboardType="email"
      />
    </View>
  );
}

Visual Variants

On Android, TextField supports multiple Material Design variants through the variant prop.

<TextField variant="filled" placeholder="Filled (Default)" />
<TextField variant="outlined" placeholder="Outlined" />
<TextField variant="none" placeholder="No Container (Android only)" />

Note: On iOS, these variants map to standard native text field styles where applicable.

Imperative Control with useTextFieldRef

For more advanced scenarios, such as programmatically focusing a field or clearing its content, use the useTextFieldRef hook and pass the resulting ref to the component.

import { TextField, useTextFieldRef, Button, View } from "@zynthjs/components";

function SearchBar() {
  const ref = useTextFieldRef();

  return (
    <View>
      <TextField ref={ref} placeholder="Search..." />
      <Button title="Clear" onPress={() => ref.clear()} />
      <Button title="Focus" onPress={() => ref.focus()} />
    </View>
  );
}

Props

PropTypeDescription
valuestringControlled text value.
defaultValuestringInitial uncontrolled text value.
placeholderstringPlaceholder text (used as a floating label on Material 3).
placeholderColorstringColor of the placeholder text.
variant"filled" | "outlined" | "none"Visual style variant. Defaults to "filled".
disabledbooleanIf true, the text field is disabled.
editablebooleanIf false, text cannot be edited. Defaults to true.
secureTextEntrybooleanIf true, masks the text for password entry.
keyboardType"default" | "numeric" | "email" | "phone" | "url"Type of keyboard to display.
returnKeyType"done" | "go" | "next" | "search" | "send"Label for the return key.
autoCapitalize"none" | "sentences" | "words" | "characters"Automatic capitalization behavior.
autoCorrectbooleanWhether to enable native autocorrect. Defaults to true.
maxLengthnumberMaximum number of characters allowed.
onChange(value: string) => voidCalled when the text changes.
onFocus() => voidCalled when the field gains focus.
onBlur() => voidCalled when the field loses focus.
onSubmit(event: { value: string }) => voidCalled when the return/submit key is pressed.
refTextFieldRefRef for imperative control.
styleStyleCustom styles for the container.
testIDstringIdentifier for automated testing.

TextFieldRef API

The TextFieldRef (created via useTextFieldRef) provides the following methods:

MethodTypeDescription
text()() => stringReturns the current text value.
setText()(value: string) => voidSets the text value programmatically.
focus()() => voidProgrammatically focuses the text field.
blur()() => voidProgrammatically blurs the text field.
clear()() => voidClears the text field.
isFocused()() => booleanReturns whether the field is currently focused.