From d1a7800bbbb426313d4bf791eea6f4779e6f4c6a Mon Sep 17 00:00:00 2001 From: Wojciech Stanisz Date: Mon, 2 Oct 2023 19:37:16 +0200 Subject: [PATCH] Fix stuff --- src/components/MagicCodeInput.js | 14 +++++++++++--- .../Profile/Contacts/ContactMethodDetailsPage.js | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/MagicCodeInput.js b/src/components/MagicCodeInput.js index 1db1acddc5d7..4669ff9efef7 100644 --- a/src/components/MagicCodeInput.js +++ b/src/components/MagicCodeInput.js @@ -102,6 +102,11 @@ function MagicCodeInput(props) { const shouldFocusLast = useRef(false); const inputWidth = useRef(0); const lastFocusedIndex = useRef(0); + const lastValue = useRef(TEXT_INPUT_EMPTY_STATE); + + useEffect(() => { + lastValue.current = input.length; + }, [input]) const blurMagicCodeInput = () => { inputRefs.current.blur(); @@ -166,6 +171,7 @@ function MagicCodeInput(props) { */ const onFocus = (event) => { if (shouldFocusLast.current) { + lastValue.current = TEXT_INPUT_EMPTY_STATE; setInput(TEXT_INPUT_EMPTY_STATE); setFocusedIndex(lastFocusedIndex.current); setEditIndex(lastFocusedIndex.current); @@ -206,9 +212,11 @@ function MagicCodeInput(props) { return; } + const addedValue = value.slice(lastValue.current.length, value.length) || value + lastValue.current = value; // Updates the focused input taking into consideration the last input // edited and the number of digits added by the user. - const numbersArr = value + const numbersArr = addedValue .trim() .split('') .slice(0, props.maxLength - editIndex); @@ -319,10 +327,10 @@ function MagicCodeInput(props) { maxLength={props.maxLength} value={input} hideFocusedState - autoComplete={props.autoComplete} + autoComplete={input.length === 0 && props.autoComplete} keyboardType={CONST.KEYBOARD_TYPE.NUMBER_PAD} onChangeText={(value) => { - onChangeText(value); + onChangeText(value) }} onKeyPress={onKeyPress} onFocus={onFocus} diff --git a/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.js b/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.js index b8c817350a38..ca890b8366be 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.js +++ b/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.js @@ -245,6 +245,7 @@ class ContactMethodDetailsPage extends Component { title={this.props.translate('contacts.removeContactMethod')} onConfirm={this.confirmDeleteAndHideModal} onCancel={() => this.toggleDeleteModal(false)} + onModalHide={() => this.validateCodeFormRef.current.focus()} prompt={this.props.translate('contacts.removeAreYouSure')} confirmText={this.props.translate('common.yesContinue')} cancelText={this.props.translate('common.cancel')}