TextField
Single-line text input. Text entry, IME composition, selection and the cursor are the platform's own — only the look changes.
Enter a valid email address.
Usage
Web (React)
const [email, setEmail] = useState("");
return (
<DotwearTextField
label="Email"
type="email"
value={email}
onChange={setEmail}
error={emailError} // undefined hides the message
/>
);
iOS (SwiftUI)
TextField("Email", text: $email)
.textFieldStyle(.dotwear)
.dotwearFieldError(emailError) // nil hides the message
React Native
const [email, setEmail] = useState("");
return (
<DotwearTextField
label="Email"
keyboardType="email-address"
value={email}
onChangeText={setEmail}
error={emailError} // undefined hides the message
/>
);
Flutter
DotwearTextField(
label: 'Email',
controller: email,
keyboardType: TextInputType.emailAddress,
error: emailError, // null hides the message
);
Variants
| Variant | Use for |
|---|---|
default | Normal input |
error | Invalid input: danger-colored border and a message below |
States
| State | Appearance |
|---|---|
| default | Border color border, background bg |
| focused | One-dot focus ring outside the border (the border width does not change, so text never moves) |
| error | Danger-colored border and message |
| disabled | Disabled color for border and text |
React API
| Prop | Description |
|---|---|
label | Required. Shown above the field and used as its accessible name |
value / onChange(value, event) | onChange receives the new string first, so onChange={setEmail} works |
error | Error message below the field (aria-invalid and aria-describedby are set). undefined hides it |
…input props | Any <input> attribute (type, placeholder, disabled, autoComplete, …) |
SwiftUI API
| API | Description |
|---|---|
.textFieldStyle(.dotwear) | Applies the Dotwear look to a TextField or SecureField |
.dotwearFieldError(_ message: String?) | Shows an error message below the field. nil hides it |
React Native API
| Prop | Description |
|---|---|
label | Required. Shown above the field and used as its accessibilityLabel |
value / onChangeText | Same as TextInput |
error | Error message below the field, also read as the field's hint. undefined or null hides it |
disabled | Not editable, in disabled colors |
…TextInput props | Any TextInput prop (placeholder, keyboardType, secureTextEntry, autoComplete, …) |
Flutter API
| Parameter | Description |
|---|---|
label | Required. Shown above the field and read as its name |
controller / onChanged | Same as TextField |
error | Error message below the field, also read as the field's hint. null hides it |
enabled / placeholder | Disabled colors / hint text shown while empty |
keyboardType, obscureText, autofillHints, … | Passed to the standard TextField |
DotwearFieldFrame | The frame alone, to wrap your own TextField (with DotwearFieldFrame.decoration(context)) |
Accessibility
- Web: the label is a <label for>, and the error is linked with aria-describedby and aria-invalid.
- iOS: VoiceOver reads the error message as the field's hint, so it is announced together with the field.
- React Native: a standard TextInput. The label is its accessibilityLabel and the error its accessibilityHint, so VoiceOver and TalkBack announce them with the field.
- Flutter: a standard TextField. The label is read as its name and the error as its hint.
- The whole 44 pt row is tappable, not just the visible border.
- Placeholders are not labels: keep a visible label when the field needs one.