Skip to content

Commit 24b1438

Browse files
authored
fix: [lw-12562] fix label position for invalid number input (#1838)
1 parent fe90ea2 commit 24b1438

File tree

2 files changed

+31
-3
lines changed
  • apps/browser-extension-wallet/src/views/bitcoin-mode/features/send/components
  • packages/common/src/ui/components/Form/Input

2 files changed

+31
-3
lines changed

apps/browser-extension-wallet/src/views/bitcoin-mode/features/send/components/SendStepOne.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const SendStepOne: React.FC<SendStepOneProps> = ({
101101
() => recommendedFees.find((f) => f.key === selectedFeeKey),
102102
[recommendedFees, selectedFeeKey]
103103
);
104-
const [customFee, setCustomFee] = useState<string>('');
104+
const [customFee, setCustomFee] = useState<string>('0');
105105
const [customFeeError, setCustomFeeError] = useState<string | undefined>();
106106
const [isValidAddress, setIsValidAddress] = useState<boolean>(false);
107107
const [invalidAddressError, setInvalidAddressError] = useState<string | undefined>();
@@ -183,6 +183,10 @@ export const SendStepOne: React.FC<SendStepOneProps> = ({
183183
}
184184
};
185185

186+
const onCustomFeeBlur = (e: React.FocusEvent<HTMLInputElement>) => {
187+
setCustomFee(e.target.value || '0');
188+
};
189+
186190
return (
187191
<Flex className={mainStyles.container} flexDirection="column" w="$fill">
188192
<Flex flexDirection="column" w="$fill" className={mainStyles.container}>
@@ -281,6 +285,8 @@ export const SendStepOne: React.FC<SendStepOneProps> = ({
281285
}}
282286
inputMode="decimal"
283287
pattern="[0-9]*[.]?[0-9]*"
288+
onBlur={onCustomFeeBlur}
289+
filledLabelOnFocus
284290
/>
285291
{customFeeError && <InputError error={customFeeError} isPopupView={isPopupView} />}
286292
</Box>

packages/common/src/ui/components/Form/Input/Input.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type inputProps = {
1313
invalid?: boolean;
1414
focus?: boolean;
1515
labelClassName?: string;
16+
filledLabelOnFocus?: boolean;
1617
} & InputProps;
1718

1819
export const Input = ({
@@ -23,10 +24,12 @@ export const Input = ({
2324
value,
2425
focus,
2526
labelClassName = '',
27+
filledLabelOnFocus,
2628
...props
2729
}: inputProps): React.ReactElement => {
2830
const inputRef = useRef(null);
2931
const [localVal, setLocalVal] = useState<string>('');
32+
const [isFocused, setIsFocused] = useState<boolean>(focus ?? false);
3033
const onValChange = (e: React.ChangeEvent<HTMLInputElement>) => {
3134
setLocalVal(e?.target?.value ?? '');
3235
onChange?.(e);
@@ -36,6 +39,16 @@ export const Input = ({
3639
setLocalVal(value ?? '');
3740
}, [value]);
3841

42+
const onFocus = (event: React.FocusEvent<HTMLInputElement>) => {
43+
setIsFocused(true);
44+
props.onFocus?.(event);
45+
};
46+
47+
const onBlur = (event: React.FocusEvent<HTMLInputElement>) => {
48+
setIsFocused(false);
49+
props.onBlur?.(event);
50+
};
51+
3952
useAutoFocus(inputRef, focus);
4053

4154
return (
@@ -44,7 +57,14 @@ export const Input = ({
4457
onChange={onValChange}
4558
{...(label && {
4659
prefix: (
47-
<div className={cn(styles.label, { [styles.filled]: localVal }, labelClassName)} data-testid="input-label">
60+
<div
61+
className={cn(
62+
styles.label,
63+
{ [styles.filled]: localVal || (filledLabelOnFocus && isFocused) },
64+
labelClassName
65+
)}
66+
data-testid="input-label"
67+
>
4868
{label}
4969
</div>
5070
)
@@ -54,9 +74,11 @@ export const Input = ({
5474
{...props}
5575
className={cn(styles.input, {
5676
...(props.className && { [props.className]: props.className }),
57-
[styles.withLabel]: localVal && label,
77+
[styles.withLabel]: (localVal || (filledLabelOnFocus && isFocused)) && label,
5878
[styles.invalid]: invalid
5979
})}
80+
onFocus={onFocus}
81+
onBlur={onBlur}
6082
/>
6183
);
6284
};

0 commit comments

Comments
 (0)