Skip to content

Commit

Permalink
fix Dropdown lists are sometimes left for revealing words after click…
Browse files Browse the repository at this point in the history
…ing on other sells
  • Loading branch information
lendihop committed Oct 17, 2023
1 parent 4d9d93b commit bb2ee60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/app/atoms/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const FormField = forwardRef<FormFieldElement, FormFieldProps>(
const secret = secretProp && textarea;
const Field = textarea ? 'textarea' : 'input';

const [passwordInputType, RevealPasswordIcon] = usePasswordToggle(smallPaddings, onReveal, revealRef, onBlur);
const [passwordInputType, RevealPasswordIcon] = usePasswordToggle(smallPaddings, id, onReveal, revealRef, onBlur);
const isPasswordInput = type === 'password';
const inputType = isPasswordInput ? passwordInputType : type;

Expand Down
2 changes: 2 additions & 0 deletions src/app/atoms/usePasswordToggle.hook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useDidUpdate, useTimeout } from 'lib/ui/hooks';

const usePasswordToggle = (
smallPaddings: boolean,
id?: string,
onReveal?: EmptyFn,
revealRef?: unknown,
handleBlur?: (e: React.FocusEvent) => void
Expand All @@ -24,6 +25,7 @@ const usePasswordToggle = (
const Icon = useMemo(
() => (
<button
id={id}
type="button"
tabIndex={1}
className={clsx('absolute inset-y-0', smallPaddings ? 'right-2' : 'right-3')}
Expand Down
17 changes: 11 additions & 6 deletions src/app/templates/SeedPhraseInput/SeedWordInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,17 @@ export const SeedWordInput: FC<SeedWordInputProps> = ({
[setValueToVariant]
);

const handleBlur = useCallback((e: React.FocusEvent) => {
if (e.relatedTarget?.tagName !== BUTTON_TAG_NAME) {
setIsBlur(true);
setFocusedVariantIndex(-1);
}
}, []);
const handleBlur = useCallback(
(e: React.FocusEvent) => {
const tag = e.relatedTarget?.tagName;

if (tag !== BUTTON_TAG_NAME || (tag === BUTTON_TAG_NAME && e.relatedTarget?.id !== id.toString())) {
setIsBlur(true);
setFocusedVariantIndex(-1);
}
},
[id]
);

const handleInputKeyDown = useCallback(
(e: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {
Expand Down

0 comments on commit bb2ee60

Please sign in to comment.