Skip to content

Commit

Permalink
fix: prevent PasswordBox and UncontrolledPasswordBox from default sub…
Browse files Browse the repository at this point in the history
…mission [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
  • Loading branch information
przemyslaw-wlodek authored and mchappell committed Nov 8, 2024
1 parent 6a9d734 commit 9ff4606
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
Expand Down
12 changes: 7 additions & 5 deletions packages/core/src/ui/components/Password/Password.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -16,14 +16,16 @@ export type PasswordProps = {
onChange: OnPasswordChange;
} & Omit<inputProps, 'onChange' | 'value'>;

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<HTMLInputElement>) => {
event.preventDefault();
props.onSubmit?.(event);
},
containerClassName: props.wrapperClassName,
errorMessage: props.error ? props.errorMessage : undefined
});
Expand Down

0 comments on commit 9ff4606

Please sign in to comment.