React Native / Inputs
TextField
Text input with a visible label, a hint or error under it, and optional leading / trailing content (an icon or a unit). Errors are announced to screen readers when they appear.
import { TextField } from "@stylhero/native";
Example
import { useState } from "react";
import { Button, Stack, TextField } from "@stylhero/native";
function TextFieldExample() {
const [email, setEmail] = useState("");
const [submitted, setSubmitted] = useState(false);
return (
<Stack gap={3}>
<TextField
label="Email"
value={email}
onChangeText={setEmail}
keyboardType="email-address"
autoCapitalize="none"
hint="We only email you about price drops."
error={submitted && !email.includes("@") ? "Enter an email address, like name@example.com" : undefined}
/>
<Button onPress={() => setSubmitted(true)}>Subscribe</Button>
</Stack>
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label required |
string |
- | Visible label, also read by screen readers. |
announceError |
boolean |
true |
Announce a new error to screen readers (iOS announcement, Android live
region). Default true. Set it to false when the screen already moves focus
to the first invalid field or shows its own error summary, so the error
isn't read twice. The error is still in the field's hint either way. |
counter |
string |
- | Short text at the end of the hint row, e.g. a "12/200" character count.
Shown only; not read by screen readers (put limits in hint instead). |
disabled |
boolean |
- | |
error |
string |
- | Error message. Turns the border red and is announced when it appears. |
hint |
string |
- | Help text under the field. Replaced by error when there is one. |
inputStyle |
StyleProp<TextStyle> |
- | Style for the input itself, e.g. a taller minHeight for several lines. |
leading |
ReactNode |
- | Icon or text before / after the input, e.g. a search icon or "$". |
ref |
Ref<ComponentRef<typeof TextInput>> |
- | |
style |
StyleProp<ViewStyle> |
- | |
trailing |
ReactNode |
- |
Also takes React Native's TextInput props (testID, accessibilityHint, onLayout…), passed to that TextInput.
Accessibility
- The visible label is the accessible name; the hint, or the error when there is one, is read as the accessibility hint.
- A new
erroris announced (iOS announcement, Android polite live region). If your form moves focus to the first invalid field instead, setannounceError={false}so it isn't read twice. - The border uses
lineStrong, which keeps 3:1 contrast.
Generated from src/components/TextField.tsx. Something wrong or missing? Open an issue.