Skip to content

Commit

Permalink
fix: skip dropdown focus on tab when word is fully typed
Browse files Browse the repository at this point in the history
  • Loading branch information
amitx13 committed Sep 10, 2024
1 parent 994f6ed commit dde5514
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/components/MnemonicPhraseInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ export default function MnemonicPhraseInput({
(value: string, index: number, selectWordFromDropdown = false) => {
const newPhrase = mnemonicPhrase.map((word, i) => (i === index ? value : word))
onChange(newPhrase)
updateFilteredWords(value, index)
if (selectWordFromDropdown) {
setShowDropdown(null)
if (!isValid) {
focusNextInput(index + 1)
}
} else {
updateFilteredWords(value, index)
}
},
[mnemonicPhrase, onChange, isValid, focusNextInput, updateFilteredWords],
Expand All @@ -94,12 +92,18 @@ export default function MnemonicPhraseInput({
} else if (e.key === 'Enter') {
const matched = MNEMONIC_WORDS.filter((word) => word.startsWith(value))
if (matched.length === 1) {
e.preventDefault()
handleInputChange(matched[0], wordIndex, true)
}
} else if (e.key === 'Tab') {
const matched = MNEMONIC_WORDS.filter((word) => word.startsWith(value))
if (matched.length === 1 && value === matched[0]) {
e.preventDefault()
focusNextInput(wordIndex + 1)
}
}
},
[filteredWords, handleInputChange],
[filteredWords, handleInputChange, focusNextInput],
)

return (
Expand Down Expand Up @@ -131,7 +135,7 @@ export default function MnemonicPhraseInput({
disabled={isDisabled ? isDisabled(wordIndex) : undefined}
onFocus={() => {
setActiveIndex(wordIndex)
updateFilteredWords(givenWord, wordIndex)
givenWord && updateFilteredWords(givenWord, wordIndex)
}}
autoFocus={isCurrentActive}
/>
Expand Down

0 comments on commit dde5514

Please sign in to comment.