Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function EmojiPickerMenu({onEmojiSelected, activeEmoji, ref}: EmojiPickerMenuPro
accessibilityLabel={translate('common.search')}
role={CONST.ROLE.PRESENTATION}
onChangeText={filterEmojis}
submitBehavior={filteredEmojis.length > 0 ? 'blurAndSubmit' : 'submit'}
blurOnSubmit={filteredEmojis.length > 0}
/>
</View>
<BaseEmojiPickerMenu
Expand Down
2 changes: 1 addition & 1 deletion src/components/EmojiPicker/EmojiPickerMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function EmojiPickerMenu({onEmojiSelected, activeEmoji, ref}: EmojiPickerMenuPro
}}
onBlur={() => setIsFocused(false)}
autoCorrect={false}
submitBehavior={filteredEmojis.length > 0 ? 'blurAndSubmit' : 'submit'}
blurOnSubmit={filteredEmojis.length > 0}
/>
</View>
<BaseEmojiPickerMenu
Expand Down
13 changes: 6 additions & 7 deletions src/components/Form/InputWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type {ComponentPropsWithoutRef, ComponentType, ForwardedRef} from 'react';
import React, {useContext} from 'react';
import type {SubmitBehavior} from 'react-native';
import type {AnimatedTextInputRef} from '@components/RNTextInput';
import RoomNameInput from '@components/RoomNameInput';
import type RoomNameInputProps from '@components/RoomNameInput/types';
Expand All @@ -18,15 +17,15 @@ const textInputBasedComponents: TextInputBasedComponents = new Set([TextInput, R
type ComputedComponentSpecificRegistrationParams = {
shouldSubmitForm: boolean;
shouldSetTouchedOnBlurOnly: boolean;
submitBehavior?: SubmitBehavior;
blurOnSubmit: boolean | undefined;
};

function computeComponentSpecificRegistrationParams({
InputComponent,
shouldSubmitForm,
multiline,
autoGrowHeight,
submitBehavior,
blurOnSubmit,
}: InputComponentBaseProps): ComputedComponentSpecificRegistrationParams {
if (textInputBasedComponents.has(InputComponent)) {
const isEffectivelyMultiline = !!multiline || !!autoGrowHeight;
Expand All @@ -47,15 +46,15 @@ function computeComponentSpecificRegistrationParams({
// calling some methods too early or twice, so we had to add this check to prevent that side effect.
// For now this side effect happened only in `TextInput` components.
shouldSetTouchedOnBlurOnly: true,
submitBehavior: isEffectivelyMultiline && shouldReallySubmitForm ? 'blurAndSubmit' : submitBehavior,
blurOnSubmit: (isEffectivelyMultiline && shouldReallySubmitForm) || blurOnSubmit,
shouldSubmitForm: shouldReallySubmitForm,
};
}

return {
shouldSetTouchedOnBlurOnly: false,
// Forward the originally provided value
submitBehavior,
blurOnSubmit,
shouldSubmitForm: !!shouldSubmitForm,
};
}
Expand All @@ -81,9 +80,9 @@ function InputWrapper<TInput extends ValidInputs, TValue extends ValueTypeKey>({
const {InputComponent, inputID, valueType = 'string', shouldSubmitForm: propShouldSubmitForm, ...rest} = props as InputComponentBaseProps;
const {registerInput} = useContext(FormContext);

const {shouldSetTouchedOnBlurOnly, submitBehavior, shouldSubmitForm} = computeComponentSpecificRegistrationParams(props as InputComponentBaseProps);
const {shouldSetTouchedOnBlurOnly, blurOnSubmit, shouldSubmitForm} = computeComponentSpecificRegistrationParams(props as InputComponentBaseProps);
// eslint-disable-next-line react-compiler/react-compiler
const {key, ...registerInputProps} = registerInput(inputID, shouldSubmitForm, {ref, valueType, ...rest, shouldSetTouchedOnBlurOnly, submitBehavior});
const {key, ...registerInputProps} = registerInput(inputID, shouldSubmitForm, {ref, valueType, ...rest, shouldSetTouchedOnBlurOnly, blurOnSubmit});

return (
<InputComponent
Expand Down
4 changes: 2 additions & 2 deletions src/components/Form/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ComponentType, FocusEvent, Key, ReactNode, Ref, RefObject} from 'react';
import type {GestureResponderEvent, StyleProp, SubmitBehavior, TextInputSubmitEditingEvent, ViewStyle} from 'react-native';
import type {GestureResponderEvent, StyleProp, TextInputSubmitEditingEvent, ViewStyle} from 'react-native';
import type {ValueOf} from 'type-fest';
import type AddPlaidBankAccount from '@components/AddPlaidBankAccount';
import type AddressSearch from '@components/AddressSearch';
Expand Down Expand Up @@ -121,7 +121,7 @@ type InputComponentBaseProps<TValue extends ValueTypeKey = ValueTypeKey> = Input
ref?: Ref<unknown>;
multiline?: boolean;
autoGrowHeight?: boolean;
submitBehavior?: SubmitBehavior;
blurOnSubmit?: boolean;
shouldSubmitForm?: boolean;
uncontrolled?: boolean;
};
Expand Down
6 changes: 3 additions & 3 deletions src/pages/signin/LoginForm/BaseLoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import type LoginFormProps from './types';

type BaseLoginFormProps = WithToggleVisibilityViewProps & LoginFormProps;

function BaseLoginForm({submitBehavior = 'submit', isVisible, ref}: BaseLoginFormProps) {
function BaseLoginForm({blurOnSubmit = false, isVisible, ref}: BaseLoginFormProps) {
const {login, setLogin} = useLogin();
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
const [closeAccount] = useOnyx(ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM, {canBeMissing: true});
Expand Down Expand Up @@ -175,7 +175,7 @@ function BaseLoginForm({submitBehavior = 'submit', isVisible, ref}: BaseLoginFor
}, [account?.isLoading]);

useEffect(() => {
if (submitBehavior === 'blurAndSubmit') {
if (blurOnSubmit) {
input.current?.blur();
}

Expand All @@ -184,7 +184,7 @@ function BaseLoginForm({submitBehavior = 'submit', isVisible, ref}: BaseLoginFor
return;
}
input.current?.focus();
}, [submitBehavior, isVisible, prevIsVisible]);
}, [blurOnSubmit, isVisible, prevIsVisible]);

useImperativeHandle(ref, () => ({
isInputFocused() {
Expand Down
3 changes: 1 addition & 2 deletions src/pages/signin/LoginForm/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type {ForwardedRef} from 'react';
import type {SubmitBehavior} from 'react-native';

type LoginFormProps = {
/** Function used to scroll to the top of the page */
scrollPageToTop?: () => void;

/** Should we dismiss the keyboard when transitioning away from the page? */
submitBehavior?: SubmitBehavior;
blurOnSubmit?: boolean;

/** Whether the content is visible. */
isVisible: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/signin/SignInPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ function SignInPage({ref}: SignInPageProps) {
<LoginForm
ref={loginFormRef}
isVisible={shouldShowLoginForm}
submitBehavior={isAccountValidated === false ? 'blurAndSubmit' : 'submit'}
blurOnSubmit={isAccountValidated === false}
// eslint-disable-next-line react-compiler/react-compiler
scrollPageToTop={signInPageLayoutRef.current?.scrollPageToTop}
/>
Expand Down