Skip to content

fix: Change login in field.setValue to use optional operator #12909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 27, 2025
32 changes: 18 additions & 14 deletions app/component-library/components/Form/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ import {
TEXTFIELD_ENDACCESSORY_TEST_ID,
} from './TextField.constants';

const TextField: React.FC<TextFieldProps> = ({
style,
size = DEFAULT_TEXTFIELD_SIZE,
startAccessory,
endAccessory,
isError = false,
inputElement,
isDisabled = false,
autoFocus = false,
onBlur,
onFocus,
...props
}) => {
const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>((
{
style,
size = DEFAULT_TEXTFIELD_SIZE,
startAccessory,
endAccessory,
isError = false,
inputElement,
isDisabled = false,
autoFocus = false,
onBlur,
onFocus,
...props
},
ref
) => {
const [isFocused, setIsFocused] = useState(autoFocus);

const { styles } = useStyles(styleSheet, {
Expand Down Expand Up @@ -87,6 +90,7 @@ const TextField: React.FC<TextFieldProps> = ({
onBlur={onBlurHandler}
onFocus={onFocusHandler}
{...props}
ref={ref}
isStateStylesDisabled
/>
)}
Expand All @@ -101,6 +105,6 @@ const TextField: React.FC<TextFieldProps> = ({
)}
</View>
);
};
});

export default TextField;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import styleSheet from './Input.styles';
import { InputProps } from './Input.types';
import { INPUT_TEST_ID } from './Input.constants';

const Input: React.FC<InputProps> = ({
const Input = React.forwardRef<HTMLInputElement, InputProps>(({
style,
textVariant = DEFAULT_TEXT_VARIANT,
isStateStylesDisabled,
Expand All @@ -23,7 +23,7 @@ const Input: React.FC<InputProps> = ({
onFocus,
autoFocus = true,
...props
}) => {
}, ref) => {
const [isFocused, setIsFocused] = useState(autoFocus);

const { styles } = useStyles(styleSheet, {
Expand Down Expand Up @@ -67,8 +67,9 @@ const Input: React.FC<InputProps> = ({
autoFocus={autoFocus}
onBlur={onBlurHandler}
onFocus={onFocusHandler}
ref={ref as React.RefObject<TextInput>}
/>
);
};
});

export default Input;
5 changes: 3 additions & 2 deletions app/components/Views/Login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
});

async componentDidMount() {
this.fieldRef.current?.focus()

Check warning on line 262 in app/components/Views/Login/index.js

View workflow job for this annotation

GitHub Actions / scripts (lint)

Missing semicolon
trace({
name: TraceName.LoginUserInteraction,
op: TraceOperation.Login,
Expand Down Expand Up @@ -419,7 +420,7 @@
password: '',
hasBiometricCredentials: false,
});
field?.setValue('');
field?.clear();
} catch (e) {
const error = e.toString();
if (
Expand Down Expand Up @@ -490,7 +491,7 @@
password: '',
hasBiometricCredentials: false,
});
field?.setValue('');
field?.clear();
} catch (error) {
this.setState({ hasBiometricCredentials: true });
Logger.log(error);
Expand Down
Loading