SwiftUI.js
Components

TextField

TextField is a control that displays an editable text interface. TextField is used to collect single-line text input from users.

TextField is a control that displays an editable text interface. TextField is used to collect single-line text input from users.

Examples

Basic Usage

Preview unavailable for this example in the static docs build.

Show code
<VStack spacing={16}>
      <TextField placeholder="Enter text here" />
      <TextField placeholder="Disabled field" disabled />
      <TextField placeholder="Email" type="email" />
    </VStack>

With Value

Preview unavailable for this example in the static docs build.

Show code
const TextFieldWithValueDemo = () => {
  const [value, setValue] = useState('Hello World')
  return (
    <VStack spacing={16}>
      <Text>Current value: {value}</Text>
      <TextField
        value={value}
        onChange={(e) => setValue(e.target.value)}
        placeholder="Type something..."
      />
    </VStack>
  )
}

API

PropTypeRequiredDescription
valuestringNoThe current value of the text field.
onChange(event: React.ChangeEvent<HTMLInputElement>) => voidNoCallback fired when the value changes.
placeholderstringNoPlaceholder text displayed when the field is empty.
disabledbooleanNoWhether the text field is disabled. Default: false
type'text' | 'email' | 'tel' | 'url' | 'search' | 'password'NoThe type of input. Defaults to 'text'. Default: 'text'

Inherits additional props from Omit<IBaseElementComponent<'input'>, 'type' | 'children'>.

Overview

TextField is a control that displays an editable text interface. TextField is used to collect single-line text input from users.

SwiftUI Correspondence: Similar to SwiftUI's TextField.

With Value

Control the text field value:

Notes

  • TextField supports controlled and uncontrolled modes
  • Use value and onChange for controlled inputs
  • TextField supports common text-entry input types such as text, email, tel, url, search, and password
  • Use placeholder to provide hints about expected input
  • TextField can be disabled with the disabled prop

Best Practices

  1. Labels: Always provide labels or placeholders for text fields
  2. Validation: Validate input on blur or submit
  3. Feedback: Provide clear feedback for invalid inputs
  4. Accessibility: Use proper labels and ARIA attributes
  5. Mobile: Ensure text fields are properly sized for mobile keyboards

On this page