Skip to content

Commit a07b3ed

Browse files
committed
optimize
1 parent 0e804f7 commit a07b3ed

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/hooks/useRovingCellRef.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@ export function useRovingCellRef(isSelected: boolean) {
99
setIsChildFocused(false);
1010
}
1111

12-
const ref = useCallback(
13-
(cell: HTMLDivElement | null) => {
14-
if (cell === null || !isSelected || cell.contains(document.activeElement)) return;
12+
const ref = useCallback((cell: HTMLDivElement | null) => {
13+
if (cell === null || cell.contains(document.activeElement)) return;
1514

16-
cell.focus({ preventScroll: true });
17-
},
18-
[isSelected]
19-
);
15+
cell.focus({ preventScroll: true });
16+
}, []);
2017

2118
function onFocus(event: React.FocusEvent<HTMLDivElement>) {
2219
if (event.target !== event.currentTarget) {
@@ -27,7 +24,7 @@ export function useRovingCellRef(isSelected: boolean) {
2724
const isFocused = isSelected && !isChildFocused;
2825

2926
return {
30-
ref,
27+
ref: isSelected ? ref : undefined,
3128
tabIndex: isFocused ? 0 : -1,
3229
onFocus
3330
};

0 commit comments

Comments
 (0)