Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
aa84b7b
fix(text-input): correct MD3 states and accessibility
likevy Sep 8, 2026
3697ac0
fix(text-input): address review feedback
likevy Sep 22, 2026
1ae85dd
refactor(text-input): pass the accessory ref straight to IconButton
likevy Oct 30, 2026
fa883f8
fix(text-input): read native descriptions only from the hint
likevy Oct 30, 2026
b6e6abd
fix(text-input): skip announcing errors present on mount
likevy Oct 30, 2026
16df4b2
test(text-input): cover indicator states through getOutlineColor
likevy Oct 30, 2026
14ce3da
docs(text-input): describe native descriptions and error announcements
likevy Oct 30, 2026
5317d18
fix(text-input): queue native error announcements
likevy Oct 30, 2026
50a3773
fix(text-input): let the disabled state override error colors
likevy Nov 17, 2026
34a2b8b
fix(text-input): render generated IDs only on web
likevy Oct 30, 2026
025ffd3
test(text-input): check the name from caller label relationships
likevy Oct 30, 2026
853cb30
test(text-input): cover the accessory accessible name warning
likevy Oct 30, 2026
0286f1e
docs(text-input): describe the 6.x behavior in the migration guide
likevy Oct 30, 2026
5e665a0
docs(text-input): scope aria-invalid notes to web
likevy Oct 30, 2026
43acbf0
test(text-input): check the disabled invalid field on web
likevy Oct 30, 2026
a2b41a3
test(text-input): check native descriptions carry no generated IDs
likevy Oct 30, 2026
cc2fa04
test(text-input): check announcement queueing on iOS only
likevy Oct 30, 2026
78088f7
test(text-input): type the accessory ref mock for React Native 0.88
likevy Nov 6, 2026
7ce603a
fix(text-input): hide the prefix and suffix while the label rests
likevy Nov 17, 2026
fa41553
docs(text-input): name React Native 0.88 in the native description note
likevy Nov 17, 2026
e3742dc
test(text-input): update snapshots after rebasing onto main
likevy Nov 17, 2026
c913d6b
fix(text-input): show the placeholder once the label has floated
likevy Nov 17, 2026
cdd2f39
test(text-input): check decorative accessories themselves are hidden
likevy Nov 17, 2026
02ca107
test(text-input): find the affix fade field by its label
likevy Nov 17, 2026
324a0fa
fix(text-input): ignore touches leaving the field when tracking hover
likevy Nov 18, 2026
df5cad7
fix(text-input): read an empty labelled field's placeholder on native
likevy Nov 18, 2026
f906f85
fix(text-input): describe the field with its prefix and suffix
likevy Nov 18, 2026
aa7a166
fix(text-input): wait for a native error to settle before announcing it
likevy Nov 18, 2026
87b98b0
docs(text-input): describe the prefix, placeholder hint and error delay
likevy Nov 18, 2026
b986bb4
refactor(text-input): read isHovered with the other shared values
likevy Nov 19, 2026
3121a0a
fix(text-input): describe a labelled field with its placeholder on web
likevy Nov 19, 2026
7e9cfbd
docs(text-input): describe how the placeholder is read on web
likevy Nov 19, 2026
b007b1d
refactor(text-input): let the hidden wrapper hide decorative icons
likevy Nov 19, 2026
0f147bb
refactor(text-input): drop the label union from TextInput.Icon props
likevy Nov 19, 2026
e435764
refactor(text-input): skip the icon label warning in production builds
likevy Nov 19, 2026
2a15877
docs(text-input): mention the warning for an unnamed actionable icon
likevy Nov 19, 2026
41e3ad8
docs(text-input): note hidden texts in tests and removed counter values
Doberjohn Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions docs/6.x/docs/guides/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,41 @@ import { TextInput, type TextInputProps } from 'react-native-paper';
/>
```

`TextInput.Icon` without a press handler is decorative: it is hidden from
assistive technology and is not a keyboard focus stop. An icon with `onPress`,
`onLongPress`, `onPressIn` or `onPressOut` requires an `aria-label` or
`accessibilityLabel` that names its action, and warns in development without
one:

```tsx
const [value, setValue] = React.useState('');

// Before (v5)
<TextInput
label="Search"
value={value}
onChangeText={setValue}
left={<TextInput.Icon icon="magnify" />}
right={<TextInput.Icon icon="close" onPress={() => setValue('')} />}
/>

// After (v6)
<TextInput
label="Search"
value={value}
onChangeText={setValue}
startAccessory={(props) => <TextInput.Icon {...props} icon="magnify" />}
endAccessory={(props) => (
<TextInput.Icon
{...props}
icon="close"
aria-label="Clear search"
onPress={() => setValue('')}
/>
)}
/>
```

#### Label and supporting text

- **`label: React.Element | string`** → **`string`**
Expand Down Expand Up @@ -903,6 +938,39 @@ const GroupError = ({ visible }: { visible: boolean }) => {
};
```

Supporting text, the character counter, `prefix` and `suffix` describe the field
instead of becoming part of its accessible name, and the prefix and suffix are
no longer read as separate text. On web, the input references them with
`aria-describedby` (the prefix and suffix while they are shown), and IDs you
pass in `aria-describedby` are kept. On Android and iOS, they are only exposed
through `accessibilityHint`, alongside any hint you pass, and the visible text
is hidden from assistive technology, so tests that find these texts with
`getByText` need `{ includeHiddenElements: true }`. Users who turn hints off,
for example with the VoiceOver Speak Hints setting, do not hear them. The
placeholder of an empty field with a label stays blank until the label floats,
so it describes the field as well: on web until the input shows it, and on
Android and iOS in the hint. The input no longer sets `aria-valuenow` and
`aria-valuemax` when the counter reaches `maxLength`.

When no label or explicit accessible name is supplied, the placeholder names the
field, including after text is entered. A disabled field always exposes its
disabled state, even when `aria-disabled={false}` is supplied.

On web, error supporting text uses `role="alert"`. On Android and iOS, a new or
changed error message is announced through `AccessibilityInfo` once it has
stayed the same for a second, so a message that changes on every keystroke is
announced once it stops changing. An error that is already shown when the field
mounts is not announced there. On web, explicit `aria-invalid` values are kept;
when omitted, validity is derived from `error` and the character counter. Custom
input renderers should forward the accessibility props they receive.

The filled indicator uses `onSurfaceVariant` and the outlined border uses
`outline` at rest. On web, both change to `onSurface` on hover, and an invalid
field changes from `error` to `onErrorContainer`. Focus takes precedence over
hover and uses `primary`, or `error` for an invalid field. A disabled field uses
the disabled colors even when `error` is set. On web it keeps `aria-invalid`; on
Android and iOS the error text stays in its hint.

#### Removed props

No direct `TextInput` equivalents for:
Expand Down
17 changes: 13 additions & 4 deletions example/src/Examples/TextInputExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ const TextInputDemo = ({ variant }: TextInputDemoProps) => {
);

const trailingIcon = (props: TextInputAccessoryProps) => (
<TextInput.Icon {...props} icon="close" onPress={() => setValue('')} />
<TextInput.Icon
{...props}
icon="close"
aria-label="Clear text"
onPress={() => setValue('')}
/>
);

const inputColor = theme.colors.onSurfaceVariant;
Expand All @@ -100,8 +105,8 @@ const TextInputDemo = ({ variant }: TextInputDemoProps) => {
{ label: 'Error', key: 'error' },
{ label: 'Disabled', key: 'disabled' },
{ label: 'Readonly', key: 'readOnly' },
{ label: 'Leading icon', key: 'leadingIcon' },
{ label: 'Trailing icon', key: 'trailingIcon' },
{ label: 'Decorative leading icon', key: 'leadingIcon' },
{ label: 'Clear text action', key: 'trailingIcon' },
{ label: 'Counter', key: 'counter' },
{ label: 'Prefix', key: 'showPrefix' },
{ label: 'Suffix', key: 'showSuffix' },
Expand All @@ -123,7 +128,11 @@ const TextInputDemo = ({ variant }: TextInputDemoProps) => {
variant={variant}
label={modifiers.label || undefined}
placeholder={modifiers.placeholder || undefined}
supportingText={modifiers.helperText || undefined}
supportingText={
controls.error
? 'Please check the entered text'
: modifiers.helperText || undefined
}
error={controls.error}
disabled={controls.disabled}
editable={!controls.readOnly}
Expand Down
126 changes: 111 additions & 15 deletions src/components/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import {
Platform,
Pressable,
Text,
TextInput as NativeTextInput,
Expand Down Expand Up @@ -28,8 +29,9 @@ import type { InternalTheme, ThemeProp } from '../../theme/types';
export type TextInputAnimationState = {
animatedLabelWrapperStyle: StyleProp<AnimatedStyle<StyleProp<ViewStyle>>>;
animatedLabelTextStyle: StyleProp<AnimatedStyle<StyleProp<TextStyle>>>;
animatedContainerStyle: StyleProp<AnimatedStyle<StyleProp<ViewStyle>>>;
animatedAffixStyle: StyleProp<AnimatedStyle<StyleProp<TextStyle>>>;
animatedActiveOutlineStyle?: StyleProp<AnimatedStyle<StyleProp<ViewStyle>>>;
isLabelFloated: boolean;
};

export type TextInputAnimationHandlers = {
Expand Down Expand Up @@ -57,17 +59,28 @@ export type TextInputColors = {
};

export type GetAccessibilityDataReturn = {
input: AccessibilityProps & { 'aria-invalid'?: boolean };
supportingText: AccessibilityProps;
counter: AccessibilityProps;
input: AccessibilityProps & {
'aria-invalid'?: TextInputProps['aria-invalid'];
'aria-describedby'?: string;
};
label: { nativeID?: string };
placeholder: AccessibilityProps & { nativeID?: string };
prefix: AccessibilityProps & { nativeID?: string };
suffix: AccessibilityProps & { nativeID?: string };
supportingText: AccessibilityProps & { nativeID?: string };
counter: AccessibilityProps & { nativeID?: string };
};

export type GetAccessibilityDataProps = {
data: TextInputProps;
id: string;
inputLength: number;
hasError: boolean;
hasCounter: boolean;
hasPrefix: boolean;
hasSuffix: boolean;
isDisabled: boolean;
isPlaceholderShown: boolean;
};

export type TextInputVariant = 'filled' | 'outlined';
Expand All @@ -76,6 +89,7 @@ export type TextInputSharedApi = {
input: React.RefObject<React.ComponentRef<typeof NativeTextInput> | null>;
theme: InternalTheme;
isFocused: boolean;
isHovered?: boolean;
isRTL: boolean;
isDisabled: boolean;
hasAccessory: boolean;
Expand Down Expand Up @@ -147,7 +161,9 @@ export type TextInputHookReturn = SharedTextInputStyleData & {
animatedActiveOutlineStyles:
| StyleProp<AnimatedStyle<StyleProp<ViewStyle>>>
| undefined;
animatedContainerStyle: StyleProp<AnimatedStyle<StyleProp<ViewStyle>>>;
animatedAffixStyle:
| StyleProp<AnimatedStyle<StyleProp<TextStyle>>>
| undefined;
animatedLabelWrapperStyles: StyleProp<AnimatedStyle<StyleProp<ViewStyle>>>;
containerStyles: StyleProp<ViewStyle>;
fieldStyles: StyleProp<ViewStyle>;
Expand All @@ -167,12 +183,16 @@ export type TextInputHookReturn = SharedTextInputStyleData & {
onFocus: (e: FocusEvent) => void;
onBlur: (e: BlurEvent) => void;
focusInput: () => void;
onHoverIn: () => void;
onHoverOut: () => void;
};

export type TextInputRenderProps = React.ComponentPropsWithoutRef<
typeof NativeTextInput
> & {
ref?: React.RefObject<React.ComponentRef<typeof NativeTextInput> | null>;
'aria-describedby'?: string;
'aria-invalid'?: TextInputProps['aria-invalid'];
};

export type TextInputHandles = Pick<
Expand All @@ -181,6 +201,18 @@ export type TextInputHandles = Pick<
>;

export type TextInputProps = NativeTextInputProps & {
/**
* Overrides the field's invalid state on web, including grammar or spelling
* errors. Defaults to the error state or an exceeded character counter.
*/
'aria-invalid'?: React.AriaAttributes['aria-invalid'];
/**
* Space-separated IDs of additional descriptions on web. The IDs of the
* rendered prefix, suffix, supporting text and character counter, and of the
* placeholder while the label covers it, are appended automatically.
* On Android and iOS, provide external descriptions with `accessibilityHint`.
*/
'aria-describedby'?: string;
/**
* Imperative handle exposing a subset of native `TextInput` methods
* with side-effect handling (e.g. `clear()` syncs internal state and animations).
Expand All @@ -204,11 +236,16 @@ export type TextInputProps = NativeTextInputProps & {
label?: string;
/**
* Supporting text to display below the input (Material Design 3).
* Associated with the field through `aria-describedby` on web and included
* in the native accessibility hint. When `error` is true, a new or changed
* message is announced. It does not become part of the field's accessible
* name.
*/
supportingText?: string;
/**
* When `true`, displays a character counter below the input on the trailing
* side, showing `currentLength/maxLength`. Requires `maxLength` to be set.
* Associated with the field alongside supporting text.
*/
counter?: boolean;
/**
Expand Down Expand Up @@ -324,7 +361,7 @@ function TextInput({
animatedActiveOutlineStyles,
animatedLabelWrapperStyles,
animatedLabelTextStyles,
animatedContainerStyle,
animatedAffixStyle,
containerStyles,
inputStyles,
prefixStyles,
Expand All @@ -343,6 +380,8 @@ function TextInput({
onChangeText,
onFocus,
onBlur,
onHoverIn,
onHoverOut,
} = useTextInput({
ref,
error,
Expand All @@ -360,8 +399,32 @@ function TextInput({
});

return (
<Pressable onPress={focusInput} accessible={false} role="none">
<View style={fieldStyles}>
<Pressable
onPress={focusInput}
onHoverIn={Platform.OS === 'web' ? undefined : onHoverIn}
onHoverOut={Platform.OS === 'web' ? undefined : onHoverOut}
accessible={false}
role="none"
>
<View
style={fieldStyles}
// Nested web Pressables contain hover events; track the whole field.
// Touches don't hover, so they neither set nor clear a mouse hover.
onPointerEnter={
Platform.OS === 'web'
? (event) => {
if (event.nativeEvent.pointerType !== 'touch') onHoverIn();
}
: undefined
}
onPointerLeave={
Platform.OS === 'web'
? (event) => {
if (event.nativeEvent.pointerType !== 'touch') onHoverOut();
}
: undefined
}
>
{/* Disabled tint overlay — filled variant only. A childless
absolutely-positioned View whose translucent fill is applied via the
`opacity` style, so it never affects label/input rendering and works
Expand All @@ -383,12 +446,24 @@ function TextInput({

{!!label && (
<Animated.View aria-hidden style={animatedLabelWrapperStyles}>
<Animated.Text style={animatedLabelTextStyles}>
<Animated.Text
{...accessibilityProps.label}
style={animatedLabelTextStyles}
>
{label}
</Animated.Text>
</Animated.View>
)}

{!!accessibilityProps.placeholder.nativeID && (
<Text
{...accessibilityProps.placeholder}
style={styles.placeholderDescription}
>
{rest.placeholder}
</Text>
)}

{renderLeadingAccessory
? renderLeadingAccessory({
style: leadingAccessoryStyles,
Expand All @@ -398,26 +473,42 @@ function TextInput({
})
: null}

<Animated.View style={[containerStyles, animatedContainerStyle]}>
{hasPrefix && <Text style={prefixStyles}>{prefix}</Text>}
{/* Keep the field visible to native accessibility even before focus. */}
<View style={containerStyles}>
Comment thread
Doberjohn marked this conversation as resolved.
Resolved
{hasPrefix && (
<Animated.Text
{...accessibilityProps.prefix}
style={[prefixStyles, animatedAffixStyle]}
>
{prefix}
</Animated.Text>
)}

{render({
ref: input,
selectionColor,
cursorColor,
placeholderTextColor,
...accessibilityProps.input,
...rest,
...accessibilityProps.input,
editable: isEditable,
readOnly: disabled ? true : rest.readOnly,
placeholder,
style: inputStyles,
onChangeText,
onFocus,
onBlur,
})}

{hasSuffix && <Text style={suffixStyles}>{suffix}</Text>}
</Animated.View>
{hasSuffix && (
<Animated.Text
{...accessibilityProps.suffix}
style={[suffixStyles, animatedAffixStyle]}
>
{suffix}
</Animated.Text>
)}
</View>

{renderTrailingAccessory ? (
renderTrailingAccessory({
Expand All @@ -427,13 +518,18 @@ function TextInput({
multiline: !!rest.multiline,
})
) : hasError ? (
<TextInputErrorIcon style={trailingAccessoryStyles} theme={theme} />
<TextInputErrorIcon
style={trailingAccessoryStyles}
disabled={isDisabled}
theme={theme}
/>
) : null}
</View>

<View style={styles.addendum}>
{!!supportingText && (
<Text
key={hasError ? 'error' : 'supporting'}
{...accessibilityProps.supportingText}
style={supportingTextStyles}
>
Expand Down
Loading
Loading