Skip to content

Commit

Permalink
Merge pull request #53761 from daledah/fix/53011
Browse files Browse the repository at this point in the history
fix: move cursor to end of input on focus
  • Loading branch information
carlosmiceli authored Dec 13, 2024
2 parents 35c2a75 + 494613b commit 29d546b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/components/TextInput/BaseTextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Browser from '@libs/Browser';
import * as InputUtils from '@libs/InputUtils';
import isInputAutoFilled from '@libs/isInputAutoFilled';
import variables from '@styles/variables';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -104,6 +105,7 @@ function BaseTextInput(

const input = useRef<HTMLInputElement | null>(null);
const isLabelActive = useRef(initialActiveLabel);
const didScrollToEndRef = useRef(false);

// AutoFocus which only works on mount:
useEffect(() => {
Expand Down Expand Up @@ -420,7 +422,19 @@ function BaseTextInput(
</Text>
</View>
)}
{isFocused && !isReadOnly && shouldShowClearButton && !!value && <TextInputClearButton onPressButton={() => setValue('')} />}
{isFocused && !isReadOnly && shouldShowClearButton && !!value && (
<View
onLayout={() => {
if (didScrollToEndRef.current || !input.current) {
return;
}
InputUtils.scrollToRight(input.current);
didScrollToEndRef.current = true;
}}
>
<TextInputClearButton onPressButton={() => setValue('')} />
</View>
)}
{!!inputProps.isLoading && (
<ActivityIndicator
size="small"
Expand Down

0 comments on commit 29d546b

Please sign in to comment.