diff --git a/src/components/TextInput/TextInput.tsx b/src/components/TextInput/TextInput.tsx
index 6db3359500..6401c5e89c 100644
--- a/src/components/TextInput/TextInput.tsx
+++ b/src/components/TextInput/TextInput.tsx
@@ -23,7 +23,10 @@ import type { AnimatedStyle } from 'react-native-reanimated';
import { useTextInput } from './hooks';
import { styles } from './styles';
import TextInputErrorIcon from './TextInputErrorIcon';
-import type { TextInputAccessoryProps } from './TextInputIcon';
+import {
+ TextInputAccessoryPlacementContext,
+ type TextInputAccessoryProps,
+} from './TextInputIcon';
import type { InternalTheme, ThemeProp } from '../../theme/types';
export type TextInputAnimationState = {
@@ -464,14 +467,16 @@ function TextInput({
)}
- {renderLeadingAccessory
- ? renderLeadingAccessory({
+ {renderLeadingAccessory ? (
+
+ {renderLeadingAccessory({
style: leadingAccessoryStyles,
error: hasError,
disabled: isDisabled,
multiline: !!rest.multiline,
- })
- : null}
+ })}
+
+ ) : null}
{/* Keep the field visible to native accessibility even before focus. */}
diff --git a/src/components/TextInput/TextInputIcon.tsx b/src/components/TextInput/TextInputIcon.tsx
index 120c93caa4..4c945b4f47 100644
--- a/src/components/TextInput/TextInputIcon.tsx
+++ b/src/components/TextInput/TextInputIcon.tsx
@@ -28,6 +28,10 @@ export type TextInputAccessoryProps = {
export type TextInputIconProps = TextInputAccessoryProps &
Omit;
+export const TextInputAccessoryPlacementContext = React.createContext<
+ 'start' | 'end'
+>('end');
+
/**
* A component to render a leading / trailing icon in the TextInput
* (return it from `startAccessory` or `endAccessory`). Accepts icon-specific props as well as
@@ -85,11 +89,12 @@ const TextInputIcon = ({
...rest
}: TextInputIconProps) => {
const theme = useInternalTheme(themeOverride);
+ const placement = React.useContext(TextInputAccessoryPlacementContext);
const color = getIconColor({
theme,
iconColor,
- hasError: error,
+ hasError: placement === 'start' ? false : error,
isDisabled: disabled,
});
diff --git a/src/components/__tests__/TextInputStates.test.tsx b/src/components/__tests__/TextInputStates.test.tsx
index 15e47691f7..7a8d1b02c9 100644
--- a/src/components/__tests__/TextInputStates.test.tsx
+++ b/src/components/__tests__/TextInputStates.test.tsx
@@ -105,3 +105,21 @@ it('uses the disabled colors for a disabled invalid field and keeps it invalid o
}
expect(screen.getByLabelText('Email')).toHaveProp('aria-invalid', true);
});
+
+it('keeps the start icon onSurfaceVariant while the end icon uses the error color', async () => {
+ await render(
+ }
+ endAccessory={(props) => }
+ />
+ );
+
+ expect(
+ screen.getByText('email', { includeHiddenElements: true })
+ ).toHaveStyle({ color: theme.colors.onSurfaceVariant });
+ expect(
+ screen.getByText('close', { includeHiddenElements: true })
+ ).toHaveStyle({ color: theme.colors.error });
+});
diff --git a/src/components/__tests__/__snapshots__/TextInput.test.tsx.snap b/src/components/__tests__/__snapshots__/TextInput.test.tsx.snap
index a815b58ef0..183e0894e2 100644
--- a/src/components/__tests__/__snapshots__/TextInput.test.tsx.snap
+++ b/src/components/__tests__/__snapshots__/TextInput.test.tsx.snap
@@ -1211,7 +1211,7 @@ exports[`renders filled TextInput with TextInput.Icon accessories when error is
style={
[
{
- "color": "rgba(179, 38, 30, 1)",
+ "color": "rgba(73, 69, 79, 1)",
"fontSize": 24,
},
[
@@ -2305,7 +2305,7 @@ exports[`renders outlined TextInput with TextInput.Icon accessories when error i
style={
[
{
- "color": "rgba(179, 38, 30, 1)",
+ "color": "rgba(73, 69, 79, 1)",
"fontSize": 24,
},
[