Skip to main content
TextField(props: {
    placeholder?: string;
    text: string;
    setText: (text: string) => void;
}): Component;
placeholder
string
Placeholder text displayed when the field is empty.
text
string
required
The current text value of the field.
setText
(text: string) => void
required
Callback invoked when the user types. Use this to update your state.

Support

Usage

Basic text field

const body = () => {
    const [name, setName] = useState("")
    return TextField({
        placeholder: "Enter your name",
        text: name,
        setText: setName
    })
}

With style modifiers

const body = () => {
    const [email, setEmail] = useState("")
    return TextField({
        placeholder: "Email address",
        text: email,
        setText: setEmail
    })
        .textFieldStyle("roundedBorder")
        .keyboardType("emailAddress")
        .autocorrectionDisabled(true)
        .padding(16)
}

Form with multiple fields

const body = () => {
    const [first, setFirst] = useState("")
    const [last, setLast] = useState("")
    return VStack({ spacing: 12 }, [
        TextField({ placeholder: "First name", text: first, setText: setFirst }),
        TextField({ placeholder: "Last name", text: last, setText: setLast }),
        Button("Submit", () => {})
    ])
        .padding(16)
}

See Also