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
5 changes: 5 additions & 0 deletions src/components/Form/FormProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ type FormProviderProps<TFormID extends OnyxFormKey = OnyxFormKey> = FormProps<TF

/** Fires at most once per frame during scrolling. */
onScroll?: () => void;

/** Prevents the submit button from triggering blur on mouse down. */
shouldPreventDefaultFocusOnPressSubmit?: boolean;
};

function FormProvider(
Expand All @@ -105,6 +108,7 @@ function FormProvider(
allowHTML = false,
isLoading = false,
shouldRenderFooterAboveSubmit = false,
shouldPreventDefaultFocusOnPressSubmit = false,
...rest
}: FormProviderProps,
forwardedRef: ForwardedRef<FormRef>,
Expand Down Expand Up @@ -438,6 +442,7 @@ function FormProvider(
isLoading={isLoading}
enabledWhenOffline={enabledWhenOffline}
shouldRenderFooterAboveSubmit={shouldRenderFooterAboveSubmit}
shouldPreventDefaultFocusOnPressSubmit={shouldPreventDefaultFocusOnPressSubmit}
>
{typeof children === 'function' ? children({inputValues}) : children}
</FormWrapper>
Expand Down
6 changes: 6 additions & 0 deletions src/components/Form/FormWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ type FormWrapperProps = ChildrenProps &

/** Fires at most once per frame during scrolling. */
onScroll?: () => void;

/** Prevents the submit button from triggering blur on mouse down. */
shouldPreventDefaultFocusOnPressSubmit?: boolean;
};

function FormWrapper({
Expand Down Expand Up @@ -89,6 +92,7 @@ function FormWrapper({
addOfflineIndicatorBottomSafeAreaPadding,
shouldSubmitButtonStickToBottom: shouldSubmitButtonStickToBottomProp,
shouldSubmitButtonBlendOpacity = false,
shouldPreventDefaultFocusOnPressSubmit = false,
onScroll = () => {},
}: FormWrapperProps) {
const styles = useThemeStyles();
Expand Down Expand Up @@ -178,6 +182,7 @@ function FormWrapper({
enterKeyEventListenerPriority={1}
shouldRenderFooterAboveSubmit={shouldRenderFooterAboveSubmit}
shouldBlendOpacity={shouldSubmitButtonBlendOpacity}
shouldPreventDefaultFocusOnPress={shouldPreventDefaultFocusOnPressSubmit}
/>
),
[
Expand Down Expand Up @@ -206,6 +211,7 @@ function FormWrapper({
submitButtonText,
submitFlexEnabled,
shouldRenderFooterAboveSubmit,
shouldPreventDefaultFocusOnPressSubmit,
],
);

Expand Down
6 changes: 6 additions & 0 deletions src/components/FormAlertWithSubmitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ type FormAlertWithSubmitButtonProps = {

/** Whether to add a bottom padding to the button */
addButtonBottomPadding?: boolean;

/** Prevents the button from triggering blur on mouse down. */
shouldPreventDefaultFocusOnPress?: boolean;
};

function FormAlertWithSubmitButton({
Expand All @@ -98,6 +101,7 @@ function FormAlertWithSubmitButton({
shouldRenderFooterAboveSubmit = false,
shouldBlendOpacity = false,
addButtonBottomPadding = true,
shouldPreventDefaultFocusOnPress = false,
}: FormAlertWithSubmitButtonProps) {
const styles = useThemeStyles();
const style = [footerContent && addButtonBottomPadding ? styles.mb3 : {}, buttonStyles];
Expand Down Expand Up @@ -130,6 +134,7 @@ function FormAlertWithSubmitButton({
danger={isSubmitActionDangerous}
medium={useSmallerSubmitButtonSize}
large={!useSmallerSubmitButtonSize}
onMouseDown={shouldPreventDefaultFocusOnPress ? (e) => e.preventDefault() : undefined}
/>
) : (
<Button
Expand All @@ -146,6 +151,7 @@ function FormAlertWithSubmitButton({
danger={isSubmitActionDangerous}
medium={useSmallerSubmitButtonSize}
large={!useSmallerSubmitButtonSize}
onMouseDown={shouldPreventDefaultFocusOnPress ? (e) => e.preventDefault() : undefined}
/>
)}
{!shouldRenderFooterAboveSubmit && footerContent}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/workspace/companyCards/addNew/CardNameStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function CardNameStep() {
const {translate} = useLocalize();
const styles = useThemeStyles();
const {inputCallbackRef} = useAutoFocusInput();
const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD);
const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD, {canBeMissing: true});

const validate = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.ADD_NEW_CARD_FEED_FORM>): FormInputErrors<typeof ONYXKEYS.FORMS.ADD_NEW_CARD_FEED_FORM> => {
const errors = getFieldRequiredErrors(values, [INPUT_IDS.CARD_TITLE]);
Expand Down Expand Up @@ -67,6 +67,7 @@ function CardNameStep() {
enabledWhenOffline
shouldHideFixErrorsAlert
addBottomSafeAreaPadding
shouldPreventDefaultFocusOnPressSubmit
>
<InputWrapper
InputComponent={TextInput}
Expand Down
Loading