Skip to content

Commit 754fe95

Browse files
authored
Merge pull request Expensify#67191 from Krishna2323/krishna2323/issue/66723
2 parents 38de4ae + 96acfc0 commit 754fe95

8 files changed

Lines changed: 18 additions & 12 deletions

File tree

src/components/AmountPicker/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {forwardRef, useState} from 'react';
22
import type {ForwardedRef} from 'react';
33
import {View} from 'react-native';
44
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
5+
import blurActiveElement from '@libs/Accessibility/blurActiveElement';
56
import CONST from '@src/CONST';
67
import callOrReturn from '@src/types/utils/callOrReturn';
78
import AmountSelectorModal from './AmountSelectorModal';
@@ -16,6 +17,7 @@ function AmountPicker({value, description, title, errorText = '', onInputChange,
1617

1718
const hidePickerModal = () => {
1819
setIsPickerVisible(false);
20+
blurActiveElement();
1921
};
2022

2123
const updateInput = (updatedValue: string) => {

src/components/Form/FormWrapper.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function FormWrapper({
8484
scrollContextEnabled = false,
8585
shouldHideFixErrorsAlert = false,
8686
disablePressOnEnter = false,
87+
enterKeyEventListenerPriority = 1,
8788
isSubmitDisabled = false,
8889
shouldRenderFooterAboveSubmit = false,
8990
isLoading = false,
@@ -179,14 +180,15 @@ function FormWrapper({
179180
enabledWhenOffline={enabledWhenOffline}
180181
isSubmitActionDangerous={isSubmitActionDangerous}
181182
disablePressOnEnter={disablePressOnEnter}
182-
enterKeyEventListenerPriority={1}
183+
enterKeyEventListenerPriority={enterKeyEventListenerPriority}
183184
shouldRenderFooterAboveSubmit={shouldRenderFooterAboveSubmit}
184185
shouldBlendOpacity={shouldSubmitButtonBlendOpacity}
185186
shouldPreventDefaultFocusOnPress={shouldPreventDefaultFocusOnPressSubmit}
186187
/>
187188
),
188189
[
189190
disablePressOnEnter,
191+
enterKeyEventListenerPriority,
190192
enabledWhenOffline,
191193
errorMessage,
192194
errors,

src/components/Form/types.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {ComponentType, FocusEvent, Key, MutableRefObject, ReactNode, Ref} from 'react';
1+
import type {ComponentType, FocusEvent, Key, ReactNode, Ref, RefObject} from 'react';
22
import type {GestureResponderEvent, NativeSyntheticEvent, StyleProp, TextInputFocusEventData, TextInputSubmitEditingEventData, ViewStyle} from 'react-native';
33
import type {ValueOf} from 'type-fest';
44
import type AddPlaidBankAccount from '@components/AddPlaidBankAccount';
@@ -166,6 +166,9 @@ type FormProps<TFormID extends OnyxFormKey = OnyxFormKey> = {
166166
/** Disable press on enter for submit button */
167167
disablePressOnEnter?: boolean;
168168

169+
/** The priority to assign the enter key event listener to buttons. 0 is the highest priority. */
170+
enterKeyEventListenerPriority?: number;
171+
169172
/** Render extra button above submit button */
170173
shouldRenderFooterAboveSubmit?: boolean;
171174
/**
@@ -182,7 +185,7 @@ type FormRef<TFormID extends OnyxFormKey = OnyxFormKey> = {
182185
submit: () => void;
183186
};
184187

185-
type InputRefs = Record<string, MutableRefObject<InputComponentBaseProps>>;
188+
type InputRefs = Record<string, RefObject<InputComponentBaseProps>>;
186189

187190
type FormInputErrors<TFormID extends OnyxFormKey = OnyxFormKey> = Partial<Record<FormOnyxKeys<TFormID>, string | undefined>>;
188191

src/components/TextPicker/TextSelectorModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ function TextSelectorModal({
142142
enabledWhenOffline
143143
shouldHideFixErrorsAlert
144144
addBottomSafeAreaPadding
145+
enterKeyEventListenerPriority={0}
145146
>
146147
<View style={styles.pb4}>{!!subtitle && <Text style={[styles.sidebarLinkText, styles.optionAlternateText]}>{subtitle}</Text>}</View>
147148
<InputWrapper

src/pages/workspace/reportFields/CreateReportFieldsPage.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ function WorkspaceCreateReportFieldsPage({
102102
setInitialCreateReportFieldsForm();
103103
}, []);
104104

105-
const [modal] = useOnyx(ONYXKEYS.MODAL, {canBeMissing: true});
106-
107105
const listValues = [...(formDraft?.[INPUT_IDS.LIST_VALUES] ?? [])].sort(localeCompare).join(', ');
108106

109107
return (
@@ -132,7 +130,6 @@ function WorkspaceCreateReportFieldsPage({
132130
submitButtonText={translate('common.save')}
133131
enabledWhenOffline
134132
shouldValidateOnBlur={false}
135-
disablePressOnEnter={!!modal?.isVisible}
136133
addBottomSafeAreaPadding
137134
>
138135
{({inputValues}) => (

src/pages/workspace/reportFields/InitialListValueSelector/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {View} from 'react-native';
44
import type {MenuItemBaseProps} from '@components/MenuItem';
55
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
66
import useOnyx from '@hooks/useOnyx';
7+
import blurActiveElement from '@libs/Accessibility/blurActiveElement';
78
import CONST from '@src/CONST';
89
import ONYXKEYS from '@src/ONYXKEYS';
910
import InitialListValueSelectorModal from './InitialListValueSelectorModal';
@@ -20,7 +21,7 @@ type InitialListValueSelectorProps = Pick<MenuItemBaseProps, 'label' | 'rightLab
2021
};
2122

2223
function InitialListValueSelector({value = '', label = '', rightLabel, subtitle = '', errorText = '', onInputChange}: InitialListValueSelectorProps, forwardedRef: ForwardedRef<View>) {
23-
const [formDraft] = useOnyx(ONYXKEYS.FORMS.WORKSPACE_REPORT_FIELDS_FORM_DRAFT);
24+
const [formDraft] = useOnyx(ONYXKEYS.FORMS.WORKSPACE_REPORT_FIELDS_FORM_DRAFT, {canBeMissing: true});
2425

2526
const [isPickerVisible, setIsPickerVisible] = useState(false);
2627

@@ -30,6 +31,7 @@ function InitialListValueSelector({value = '', label = '', rightLabel, subtitle
3031

3132
const hidePickerModal = () => {
3233
setIsPickerVisible(false);
34+
blurActiveElement();
3335
};
3436

3537
const updateValueInput = (initialValue: string) => {

src/pages/workspace/reportFields/TypeSelector/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {View} from 'react-native';
55
import type {MenuItemBaseProps} from '@components/MenuItem';
66
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
77
import useLocalize from '@hooks/useLocalize';
8-
import * as WorkspaceReportFieldUtils from '@libs/WorkspaceReportFieldUtils';
8+
import blurActiveElement from '@libs/Accessibility/blurActiveElement';
9+
import {getReportFieldTypeTranslationKey} from '@libs/WorkspaceReportFieldUtils';
910
import type {ReportFieldItemType} from '@pages/workspace/reportFields/ReportFieldTypePicker';
1011
import CONST from '@src/CONST';
1112
import type {PolicyReportFieldType} from '@src/types/onyx/Policy';
@@ -36,6 +37,7 @@ function TypeSelector({value, label = '', rightLabel, subtitle = '', errorText =
3637

3738
const hidePickerModal = () => {
3839
setIsPickerVisible(false);
40+
blurActiveElement();
3941
};
4042

4143
const updateTypeInput = (reportField: ReportFieldItemType) => {
@@ -49,7 +51,7 @@ function TypeSelector({value, label = '', rightLabel, subtitle = '', errorText =
4951
<MenuItemWithTopDescription
5052
ref={forwardedRef}
5153
shouldShowRightIcon
52-
title={value ? Str.recapitalize(translate(WorkspaceReportFieldUtils.getReportFieldTypeTranslationKey(value as PolicyReportFieldType))) : ''}
54+
title={value ? Str.recapitalize(translate(getReportFieldTypeTranslationKey(value as PolicyReportFieldType))) : ''}
5355
description={label}
5456
rightLabel={rightLabel}
5557
brickRoadIndicator={errorText ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}

src/pages/workspace/taxes/WorkspaceCreateTaxPage.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import ScreenWrapper from '@components/ScreenWrapper';
1010
import Text from '@components/Text';
1111
import TextPicker from '@components/TextPicker';
1212
import useLocalize from '@hooks/useLocalize';
13-
import useOnyx from '@hooks/useOnyx';
1413
import useThemeStyles from '@hooks/useThemeStyles';
1514
import {createPolicyTax, getNextTaxCode, getTaxValueWithPercentage, validateTaxName, validateTaxValue} from '@libs/actions/TaxRate';
1615
import Navigation from '@libs/Navigation/Navigation';
@@ -37,7 +36,6 @@ function WorkspaceCreateTaxPage({
3736
}: WorkspaceCreateTaxPageProps) {
3837
const styles = useThemeStyles();
3938
const {translate} = useLocalize();
40-
const [modal] = useOnyx(ONYXKEYS.MODAL, {canBeMissing: true});
4139

4240
const submitForm = useCallback(
4341
({value, ...values}: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_NEW_TAX_FORM>) => {
@@ -90,7 +88,6 @@ function WorkspaceCreateTaxPage({
9088
submitButtonText={translate('common.save')}
9189
enabledWhenOffline
9290
shouldValidateOnBlur={false}
93-
disablePressOnEnter={!!modal?.isVisible}
9491
addBottomSafeAreaPadding
9592
>
9693
<View style={styles.mhn5}>

0 commit comments

Comments
 (0)