Skip to content

Commit

Permalink
Prevent form submission on Enter
Browse files Browse the repository at this point in the history
  • Loading branch information
xpaczka committed Dec 15, 2023
1 parent 8316b24 commit c7bf65c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ui/components/Shared/SharedButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type Props = {
*/
iconPosition?: "left" | "right"
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void
onKeyDown?: (event: React.KeyboardEvent<HTMLButtonElement>) => void
isDisabled?: boolean
hideEvents?: boolean
linkTo?: History.LocationDescriptor<unknown>
Expand All @@ -45,6 +46,7 @@ export default function SharedButton(
type,
size,
onClick,
onKeyDown,
isDisabled = false,
hideEvents = true,
iconSmall,
Expand Down Expand Up @@ -107,6 +109,7 @@ export default function SharedButton(
{ center },
)}
onClick={handleClick}
onKeyDown={onKeyDown}
style={style}
>
{isShowingLoadingSpinner && (
Expand Down
12 changes: 11 additions & 1 deletion ui/pages/Onboarding/Tabbed/ViewOnlyWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ export default function ViewOnlyWallet(): ReactElement {
setRedirect(true)
}, [dispatch, addressOnNetwork, isValidating])

const preventSubmitOnEnter = useCallback(
(event: React.KeyboardEvent<HTMLButtonElement>) => {
if (event.key === "Enter" && isValidating) {
event.preventDefault()
}
},
[isValidating],
)

// Redirect to the final onboarding tab once an account is set
if (redirect) {
return <Redirect to={OnboardingRoutes.ONBOARDING_COMPLETE} />
Expand Down Expand Up @@ -102,7 +111,8 @@ export default function ViewOnlyWallet(): ReactElement {
type="primary"
size="large"
onClick={handleSubmitViewOnlyAddress}
isDisabled={addressOnNetwork === undefined}
onKeyDown={preventSubmitOnEnter}
isDisabled={addressOnNetwork === undefined || isValidating}
showLoadingOnClick
center
isFormSubmit
Expand Down

0 comments on commit c7bf65c

Please sign in to comment.