Skip to content

Commit

Permalink
Merge pull request #46948 from daledah/fix/45416
Browse files Browse the repository at this point in the history
fix: press Tab to move around magic code input
  • Loading branch information
srikarparsi authored Aug 13, 2024
2 parents 3b0f99e + b569de3 commit 420c2a1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/MagicCodeInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {ForwardedRef} from 'react';
import type {ForwardedRef, KeyboardEvent} from 'react';
import React, {forwardRef, useEffect, useImperativeHandle, useRef, useState} from 'react';
import type {NativeSyntheticEvent, TextInputFocusEventData, TextInputKeyPressEventData} from 'react-native';
import {StyleSheet, View} from 'react-native';
Expand Down Expand Up @@ -332,6 +332,15 @@ function MagicCodeInput(
}
setInput(TEXT_INPUT_EMPTY_STATE);
onFulfill(value);
} else if (keyValue === 'Tab' && focusedIndex !== undefined) {
const newFocusedIndex = (event as unknown as KeyboardEvent).shiftKey ? focusedIndex - 1 : focusedIndex + 1;
if (newFocusedIndex >= 0 && newFocusedIndex < maxLength) {
setInputAndIndex(newFocusedIndex);
inputRefs.current?.focus();
if (event?.preventDefault) {
event.preventDefault();
}
}
}
};

Expand Down

0 comments on commit 420c2a1

Please sign in to comment.