Skip to content

Commit b3b7460

Browse files
authored
Merge pull request #90125 from software-mansion-labs/@GCyganek/fix/split-list-handle-input-focus
Fix Split - The input field loses focus while typing the split amount.
2 parents 09a5925 + 8b7f86c commit b3b7460

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
import {useCallback} from 'react';
12
import type {SplitListItemType} from '@components/SelectionList/ListItem/types';
23
import useIsInLandscapeMode from '@hooks/useIsInLandscapeMode';
34
import type UseHandleInputFocusProps from './types';
45

56
function useHandleInputFocus({listRef}: UseHandleInputFocusProps) {
67
const isInLandscapeMode = useIsInLandscapeMode();
78

8-
return (item: SplitListItemType) => {
9-
if (!listRef.current || isInLandscapeMode) {
10-
return;
11-
}
12-
listRef.current?.scrollToFocusedInput(item);
13-
};
9+
return useCallback(
10+
(item: SplitListItemType) => {
11+
if (!listRef.current || isInLandscapeMode) {
12+
return;
13+
}
14+
listRef.current?.scrollToFocusedInput(item);
15+
},
16+
[listRef, isInLandscapeMode],
17+
);
1418
}
1519

1620
export default useHandleInputFocus;
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
import {useCallback} from 'react';
12
import type {SplitListItemType} from '@components/SelectionList/ListItem/types';
23
import type UseHandleInputFocusProps from './types';
34

45
function useHandleInputFocus({listRef}: UseHandleInputFocusProps) {
5-
return (item: SplitListItemType) => {
6-
if (!listRef.current) {
7-
return;
8-
}
9-
listRef.current?.scrollToFocusedInput(item);
10-
};
6+
return useCallback(
7+
(item: SplitListItemType) => {
8+
if (!listRef.current) {
9+
return;
10+
}
11+
listRef.current?.scrollToFocusedInput(item);
12+
},
13+
[listRef],
14+
);
1115
}
1216

1317
export default useHandleInputFocus;

0 commit comments

Comments
 (0)