Skip to content

Commit

Permalink
Merge pull request #42033 from Krishna2323/krishna2323/issue/41800
Browse files Browse the repository at this point in the history
fix: Taxes - When creating a Tax, the keyboard does not automatically appear in the Name menu.
  • Loading branch information
MonilBhavsar authored May 15, 2024
2 parents edd1719 + 25f7928 commit 7ef8e8c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
29 changes: 28 additions & 1 deletion src/components/TextPicker/TextSelectorModal.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, {useState} from 'react';
import {useFocusEffect} from '@react-navigation/native';
import React, {useCallback, useRef, useState} from 'react';
import {Keyboard, View} from 'react-native';
import Button from '@components/Button';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import Modal from '@components/Modal';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
import TextInput from '@components/TextInput';
import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
Expand All @@ -19,6 +21,25 @@ function TextSelectorModal({value, description = '', onValueSelected, isVisible,
const [currentValue, setValue] = useState(value);
const paddingStyle = usePaddingStyle();

const inputRef = useRef<BaseTextInputRef | null>(null);
const focusTimeoutRef = useRef<NodeJS.Timeout | null>(null);

useFocusEffect(
useCallback(() => {
focusTimeoutRef.current = setTimeout(() => {
if (inputRef.current && isVisible) {
inputRef.current.focus();
}
return () => {
if (!focusTimeoutRef.current || !isVisible) {
return;
}
clearTimeout(focusTimeoutRef.current);
};
}, CONST.ANIMATED_TRANSITION);
}, [isVisible]),
);

return (
<Modal
type={CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED}
Expand Down Expand Up @@ -50,6 +71,12 @@ function TextSelectorModal({value, description = '', onValueSelected, isVisible,
{...rest}
value={currentValue}
onInputChange={setValue}
ref={(ref) => {
if (!ref) {
return;
}
inputRef.current = ref;
}}
/>
</View>
<Button
Expand Down
1 change: 0 additions & 1 deletion src/pages/workspace/taxes/WorkspaceCreateTaxPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ function WorkspaceCreateTaxPage({
maxLength={CONST.TAX_RATES.NAME_MAX_LENGTH}
multiline={false}
role={CONST.ROLE.PRESENTATION}
autoFocus
/>
<InputWrapper
InputComponent={AmountPicker}
Expand Down

0 comments on commit 7ef8e8c

Please sign in to comment.