fix: ui bugs
This commit is contained in:
@@ -57,10 +57,20 @@ const DigitInput: React.FC<DigitInputProps> = ({
|
||||
event: KeyboardEvent<HTMLDivElement>,
|
||||
index: number,
|
||||
) => {
|
||||
if (event.key === 'Backspace' && code[index]) {
|
||||
if (event.key === 'Backspace') {
|
||||
event.preventDefault();
|
||||
handleChange('', index);
|
||||
if (index > 0) inputRefs.current[index - 1]?.focus();
|
||||
|
||||
if (code[index]) {
|
||||
// We clear the current value.
|
||||
handleChange('', index);
|
||||
} else if (index > 0) {
|
||||
// We move focus to the previous input and SELECT its content.
|
||||
const prevInput = inputRefs.current[index - 1];
|
||||
if (prevInput) {
|
||||
prevInput.focus();
|
||||
prevInput.select();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user