From 9ff46065bb15aa5943e2e990529c8bcecfd243f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20W=C5=82odek?= Date: Fri, 8 Nov 2024 10:45:51 +0100 Subject: [PATCH] fix: prevent PasswordBox and UncontrolledPasswordBox from default submission [LW-11807] (#1521) - override default onSubmit and use event.preventDefault() (default behaviour reloads the window) - this solves the issue in Lace and proper fix should be done in `@input-output-hk/lace-ui-toolkit`, but it requires bigger refactor of all input components --- .../restore-wallet/steps/EnterPgpPrivateKey.tsx | 4 +++- .../core/src/ui/components/Password/Password.tsx | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/restore-wallet/steps/EnterPgpPrivateKey.tsx b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/restore-wallet/steps/EnterPgpPrivateKey.tsx index 9314a23d19..aebf09c9ea 100644 --- a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/restore-wallet/steps/EnterPgpPrivateKey.tsx +++ b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/restore-wallet/steps/EnterPgpPrivateKey.tsx @@ -259,7 +259,9 @@ export const EnterPgpPrivateKey: VFC = () => { }} label={i18n.t('core.paperWallet.privatePgpKeyPassphraseLabel')} value={pgpInfo.pgpKeyPassphrase || ''} - onSubmit={null} + onSubmit={(event) => { + event.preventDefault(); + }} disabled={pgpInfo.privateKeyIsDecrypted} data-testid="pgp-passphrase" /> diff --git a/packages/core/src/ui/components/Password/Password.tsx b/packages/core/src/ui/components/Password/Password.tsx index 623b956671..d50103e025 100644 --- a/packages/core/src/ui/components/Password/Password.tsx +++ b/packages/core/src/ui/components/Password/Password.tsx @@ -1,8 +1,8 @@ -import React from 'react'; +import React, { FormEvent } from 'react'; import { + OnPasswordChange, UncontrolledPasswordBox, - UncontrolledPasswordBoxProps, - OnPasswordChange + UncontrolledPasswordBoxProps } from '@input-output-hk/lace-ui-toolkit'; import { inputProps } from '@lace/common'; @@ -16,14 +16,16 @@ export type PasswordProps = { onChange: OnPasswordChange; } & Omit; -const noop = (): void => void 0; const mapProps = (props: PasswordProps): UncontrolledPasswordBoxProps => ({ ...props, testId: props['data-testid'] || props.dataTestId, label: props.label || '', size: undefined, prefix: undefined, - onSubmit: props.onSubmit || noop, + onSubmit: (event: FormEvent) => { + event.preventDefault(); + props.onSubmit?.(event); + }, containerClassName: props.wrapperClassName, errorMessage: props.error ? props.errorMessage : undefined });