Skip to content

Commit

Permalink
Fix stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtus7 committed Oct 2, 2023
1 parent 6aa803f commit d1a7800
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/components/MagicCodeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
Expand Down

0 comments on commit d1a7800

Please sign in to comment.