Skip to content

Commit a3d5114

Browse files
authored
Merge pull request Expensify#69446 from software-mansion-labs/jakubkalinski0/Resolving-issues-regarding-the-disfunctional-autoFocus
Resolving issues regarding the dysfunctional autoFocus
2 parents 4c098ba + 9fde703 commit a3d5114

13 files changed

Lines changed: 54 additions & 54 deletions

File tree

src/components/AmountForm.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type AmountFormProps = {
4444
hideCurrencySymbol?: boolean;
4545

4646
/** Reference to the outer element */
47-
forwardedRef?: ForwardedRef<BaseTextInputRef>;
47+
ref?: ForwardedRef<BaseTextInputRef>;
4848
} & Pick<BaseTextInputProps, 'autoFocus' | 'autoGrowExtraSpace' | 'autoGrowMarginSide'>;
4949

5050
/**
@@ -65,7 +65,7 @@ function AmountForm({
6565
autoFocus,
6666
autoGrowExtraSpace,
6767
autoGrowMarginSide,
68-
forwardedRef,
68+
ref,
6969
}: AmountFormProps) {
7070
const styles = useThemeStyles();
7171
const decimals = decimalsProp ?? getCurrencyDecimals(currency);
@@ -78,12 +78,12 @@ function AmountForm({
7878
displayAsTextInput={displayAsTextInput}
7979
onInputChange={onInputChange}
8080
onSymbolButtonPress={onCurrencyButtonPress}
81-
forwardedRef={(ref: BaseTextInputRef | null) => {
82-
if (typeof forwardedRef === 'function') {
83-
forwardedRef(ref);
84-
} else if (forwardedRef && 'current' in forwardedRef) {
85-
// eslint-disable-next-line no-param-reassign, react-compiler/react-compiler
86-
forwardedRef.current = ref;
81+
ref={(newRef: BaseTextInputRef | null) => {
82+
if (typeof ref === 'function') {
83+
ref(newRef);
84+
} else if (ref && 'current' in ref) {
85+
// eslint-disable-next-line no-param-reassign
86+
ref.current = newRef;
8787
}
8888
}}
8989
symbol={getLocalizedCurrencySymbol(currency) ?? ''}

src/components/AmountPicker/AmountSelectorModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function AmountSelectorModal({value, description = '', onValueSelected, isVisibl
6969
{...rest}
7070
value={currentValue}
7171
onInputChange={setValue}
72-
forwardedRef={(ref) => inputCallbackRef(ref)}
72+
ref={(ref) => inputCallbackRef(ref)}
7373
/>
7474
<Button
7575
success

src/components/Form/FormProvider.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ type FormProviderProps<TFormID extends OnyxFormKey = OnyxFormKey> = FormProps<TF
100100
shouldPreventDefaultFocusOnPressSubmit?: boolean;
101101

102102
/** Reference to the outer element */
103-
forwardedRef?: ForwardedRef<FormRef>;
103+
ref?: ForwardedRef<FormRef>;
104104
};
105105

106106
function FormProvider({
@@ -117,7 +117,7 @@ function FormProvider({
117117
shouldRenderFooterAboveSubmit = false,
118118
shouldUseStrictHtmlTagValidation = false,
119119
shouldPreventDefaultFocusOnPressSubmit = false,
120-
forwardedRef,
120+
ref,
121121
...rest
122122
}: FormProviderProps) {
123123
const [network] = useOnyx(ONYXKEYS.NETWORK, {canBeMissing: true});
@@ -306,7 +306,7 @@ function FormProvider({
306306
[errors, formID],
307307
);
308308

309-
useImperativeHandle(forwardedRef, () => ({
309+
useImperativeHandle(ref, () => ({
310310
resetForm,
311311
resetErrors,
312312
resetFormFieldError,

src/components/MoneyRequestAmountInput.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ type MoneyRequestAmountInputProps = {
105105
shouldWrapInputInContainer?: boolean;
106106

107107
/** Reference to the outer element */
108-
forwardedRef?: ForwardedRef<BaseTextInputRef>;
108+
ref?: ForwardedRef<BaseTextInputRef>;
109109
} & Pick<TextInputWithSymbolProps, 'autoGrowExtraSpace' | 'submitBehavior' | 'shouldUseDefaultLineHeightForPrefix'>;
110110

111111
type Selection = {
@@ -143,7 +143,7 @@ function MoneyRequestAmountInput({
143143
shouldApplyPaddingToContainer = false,
144144
shouldUseDefaultLineHeightForPrefix = true,
145145
shouldWrapInputInContainer = true,
146-
forwardedRef,
146+
ref,
147147
...props
148148
}: MoneyRequestAmountInputProps) {
149149
const textInput = useRef<BaseTextInputRef | null>(null);
@@ -183,24 +183,24 @@ function MoneyRequestAmountInput({
183183
onSymbolButtonPress={onCurrencyButtonPress}
184184
onInputChange={onAmountChange}
185185
onBlur={formatAmount}
186-
forwardedRef={(ref) => {
187-
if (typeof forwardedRef === 'function') {
188-
forwardedRef(ref);
189-
} else if (forwardedRef?.current) {
190-
// eslint-disable-next-line no-param-reassign, react-compiler/react-compiler
191-
forwardedRef.current = ref;
186+
ref={(newRef) => {
187+
if (typeof ref === 'function') {
188+
ref(newRef);
189+
} else if (ref?.current) {
190+
// eslint-disable-next-line no-param-reassign
191+
ref.current = newRef;
192192
}
193193
// eslint-disable-next-line react-compiler/react-compiler
194-
textInput.current = ref;
194+
textInput.current = newRef;
195195
}}
196-
numberFormRef={(ref) => {
196+
numberFormRef={(newRef) => {
197197
if (typeof moneyRequestAmountInputRef === 'function') {
198-
moneyRequestAmountInputRef(ref);
198+
moneyRequestAmountInputRef(newRef);
199199
} else if (moneyRequestAmountInputRef && 'current' in moneyRequestAmountInputRef) {
200200
// eslint-disable-next-line react-compiler/react-compiler, no-param-reassign
201-
moneyRequestAmountInputRef.current = ref;
201+
moneyRequestAmountInputRef.current = newRef;
202202
}
203-
numberFormRef.current = ref;
203+
numberFormRef.current = newRef;
204204
}}
205205
symbol={getLocalizedCurrencySymbol(currency) ?? ''}
206206
symbolPosition={CONST.TEXT_INPUT_SYMBOL_POSITION.PREFIX}

src/components/NumberWithSymbolForm.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type NumberWithSymbolFormProps = {
5353
shouldWrapInputInContainer?: boolean;
5454

5555
/** Reference to the outer element */
56-
forwardedRef?: ForwardedRef<BaseTextInputRef>;
56+
ref?: ForwardedRef<BaseTextInputRef>;
5757
} & Omit<TextInputWithSymbolProps, 'formattedAmount' | 'onAmountChange' | 'placeholder' | 'onSelectionChange' | 'onKeyPress' | 'onMouseDown' | 'onMouseUp'>;
5858

5959
type NumberWithSymbolFormRef = {
@@ -108,7 +108,7 @@ function NumberWithSymbolForm({
108108
shouldApplyPaddingToContainer = false,
109109
shouldUseDefaultLineHeightForPrefix = true,
110110
shouldWrapInputInContainer = true,
111-
forwardedRef,
111+
ref,
112112
...props
113113
}: NumberWithSymbolFormProps) {
114114
const styles = useThemeStyles();
@@ -318,12 +318,12 @@ function NumberWithSymbolForm({
318318
accessibilityLabel={label}
319319
value={formattedNumber}
320320
onChangeText={setFormattedNumber}
321-
ref={(ref: BaseTextInputRef | null) => {
322-
if (typeof forwardedRef === 'function') {
323-
forwardedRef(ref);
324-
} else if (forwardedRef && 'current' in forwardedRef) {
325-
// eslint-disable-next-line react-compiler/react-compiler, no-param-reassign
326-
forwardedRef.current = ref;
321+
ref={(newRef: BaseTextInputRef | null) => {
322+
if (typeof ref === 'function') {
323+
ref(newRef);
324+
} else if (ref && 'current' in ref) {
325+
// eslint-disable-next-line no-param-reassign
326+
ref.current = newRef;
327327
}
328328
}}
329329
prefixCharacter={symbol}
@@ -348,14 +348,14 @@ function NumberWithSymbolForm({
348348
onChangeAmount={setNewNumber}
349349
onSymbolButtonPress={onSymbolButtonPress}
350350
placeholder={numberFormat(0)}
351-
ref={(ref: BaseTextInputRef | null) => {
352-
if (typeof forwardedRef === 'function') {
353-
forwardedRef(ref);
354-
} else if (forwardedRef && 'current' in forwardedRef) {
351+
ref={(newRef: BaseTextInputRef | null) => {
352+
if (typeof ref === 'function') {
353+
ref(newRef);
354+
} else if (ref && 'current' in ref) {
355355
// eslint-disable-next-line no-param-reassign
356-
forwardedRef.current = ref;
356+
ref.current = newRef;
357357
}
358-
textInput.current = ref;
358+
textInput.current = newRef;
359359
}}
360360
symbol={symbol}
361361
hideSymbol={hideSymbol}

src/components/SubStepForms/AddressStep.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function AddressStep<TFormID extends keyof OnyxFormValuesMapping>({
134134
validate={customValidate ?? validate}
135135
onSubmit={onSubmit}
136136
style={[styles.mh5, styles.flexGrow1]}
137-
forwardedRef={formRef}
137+
ref={formRef}
138138
enabledWhenOffline
139139
>
140140
<View>

src/pages/iou/MoneyRequestAmountForm.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function MoneyRequestAmountForm({
7373
shouldKeepUserInput = false,
7474
chatReportID,
7575
hideCurrencySymbol = false,
76-
forwardedRef,
76+
ref,
7777
}: MoneyRequestAmountFormProps) {
7878
const styles = useThemeStyles();
7979
const {isExtraSmallScreenHeight} = useResponsiveLayout();
@@ -217,14 +217,14 @@ function MoneyRequestAmountForm({
217217
setFormError('');
218218
}}
219219
shouldShowBigNumberPad={canUseTouchScreen}
220-
forwardedRef={(ref) => {
221-
if (typeof forwardedRef === 'function') {
222-
forwardedRef(ref);
223-
} else if (forwardedRef && 'current' in forwardedRef) {
224-
// eslint-disable-next-line no-param-reassign, react-compiler/react-compiler
225-
forwardedRef.current = ref;
220+
ref={(newRef) => {
221+
if (typeof ref === 'function') {
222+
ref(newRef);
223+
} else if (ref && 'current' in ref) {
224+
// eslint-disable-next-line no-param-reassign
225+
ref.current = newRef;
226226
}
227-
textInput.current = ref;
227+
textInput.current = newRef;
228228
}}
229229
moneyRequestAmountInputRef={moneyRequestAmountInputRef}
230230
shouldKeepUserInput={shouldKeepUserInput}

src/pages/iou/request/step/IOURequestStepAmount.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ function IOURequestStepAmount({
332332
skipConfirmation={shouldSkipConfirmation ?? false}
333333
iouType={iouType}
334334
policyID={policy?.id}
335-
forwardedRef={(e) => {
335+
ref={(e) => {
336336
textInput.current = e;
337337
}}
338338
shouldKeepUserInput={transaction?.shouldShowOriginalAmount}

src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function IOURequestStepTaxAmountPage({
152152
currency={currency}
153153
amount={Math.abs(transactionDetails?.taxAmount ?? 0)}
154154
taxAmount={getTaxAmount(currentTransaction, policy, currency, !!(backTo || isEditing))}
155-
forwardedRef={(e) => {
155+
ref={(e) => {
156156
textInput.current = e;
157157
}}
158158
onCurrencyButtonPress={navigateToCurrencySelectionPage}

src/pages/settings/Profile/CustomStatus/StatusPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function StatusPage() {
189189
<FormProvider
190190
formID={ONYXKEYS.FORMS.SETTINGS_STATUS_SET_FORM}
191191
style={[styles.flexGrow1, styles.flex1]}
192-
forwardedRef={formRef}
192+
ref={formRef}
193193
submitButtonText={translate('statusPage.save')}
194194
submitButtonStyles={[styles.mh5, styles.flexGrow1]}
195195
onSubmit={updateStatus}

0 commit comments

Comments
 (0)