Skip to content

Commit b584e5b

Browse files
committed
feat(rff-rn-paper): add support for autoFocus property to trigger focus when neccessary
1 parent e2a6e1c commit b584e5b

File tree

1 file changed

+12
-1
lines changed
  • packages/rff-rn-paper/src/components/TextInput

1 file changed

+12
-1
lines changed

packages/rff-rn-paper/src/components/TextInput/index.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@ export type TextInputProps = BaseInputProps &
5252
* Property that represents the input styles
5353
*/
5454
style?: any;
55+
/**
56+
* Property to set autoFocus in Input
57+
*/
58+
autoFocus?: boolean;
5559
};
5660

5761
export const TextInput: React.FC<TextInputProps> = React.forwardRef(({
62+
autoFocus = false,
5863
input: { onChange, onFocus, onBlur, value, ...InputProps },
5964
meta,
6065
label,
@@ -71,14 +76,20 @@ export const TextInput: React.FC<TextInputProps> = React.forwardRef(({
7176

7277
useEffect(() => {
7378
if (secureTextEntry && style && style.hasOwnProperty("fontFamily")) {
74-
textInputRef.current.setNativeProps({
79+
textInputRef?.current?.setNativeProps?.({
7580
style: {
7681
fontFamily: style.fontFamily
7782
}
7883
})
7984
}
8085
}, [secureTextEntry])
8186

87+
useEffect(() => {
88+
if (autoFocus) {
89+
textInputRef?.current?.focus?.();
90+
}
91+
}, [autoFocus])
92+
8293
return (
8394
<Container
8495
{...ContainerProps}

0 commit comments

Comments
 (0)