From b569de305fe5532626cff16f68fdf67afef90797 Mon Sep 17 00:00:00 2001 From: daledah Date: Wed, 7 Aug 2024 16:21:58 +0700 Subject: [PATCH] fix: press Tab to move around magic code input --- src/components/MagicCodeInput.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/MagicCodeInput.tsx b/src/components/MagicCodeInput.tsx index 2fae3cc89597..79c2445f7ae7 100644 --- a/src/components/MagicCodeInput.tsx +++ b/src/components/MagicCodeInput.tsx @@ -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'; @@ -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(); + } + } } };