Skip to content

Commit

Permalink
Handle timeout clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasTy committed Jul 11, 2024
1 parent c50b47f commit a003573
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const addPositionPropertiesToSections = <TSection extends FieldSection>(
export const useFieldV6TextField: UseFieldTextField<false> = (params) => {
const isRtl = useRtl();
const focusTimeoutRef = React.useRef<ReturnType<typeof setTimeout>>();
const selectionSyncTimeoutRef = React.useRef<ReturnType<typeof setTimeout>>();

const {
forwardedProps: {
Expand Down Expand Up @@ -162,7 +163,8 @@ export const useFieldV6TextField: UseFieldTextField<false> = (params) => {
inputRef.current.setSelectionRange(selectionStart, selectionEnd);
}
}
setTimeout(() => {
clearTimeout(selectionSyncTimeoutRef.current);
selectionSyncTimeoutRef.current = setTimeout(() => {
// handle case when the selection is not updated correctly
// could happen on Android
if (
Expand Down Expand Up @@ -436,6 +438,7 @@ export const useFieldV6TextField: UseFieldTextField<false> = (params) => {

return () => {
clearTimeout(focusTimeoutRef.current);
clearTimeout(selectionSyncTimeoutRef.current);
};
}, []); // eslint-disable-line react-hooks/exhaustive-deps

Expand Down

0 comments on commit a003573

Please sign in to comment.