-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Refactor useRovingCellRef, fix test warnings #2883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2883 +/- ##
==========================================
- Coverage 96.24% 96.22% -0.02%
==========================================
Files 38 38
Lines 1250 1246 -4
Branches 391 392 +1
==========================================
- Hits 1203 1199 -4
Misses 47 47
|
src/hooks/useRovingCellRef.ts
Outdated
(cell: HTMLDivElement | null) => { | ||
if (cell === null || !isSelected || cell.contains(document.activeElement)) return; | ||
|
||
cell.focus({ preventScroll: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only concern is if it is possible to have a stale ref in a ref callback. Not sure why is useLayoutEffect
is the recommended approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYM by stale ref?
useLayoutEffect
would use that same ref anyway.
src/hooks/useRovingCellRef.ts
Outdated
|
||
return { | ||
ref, | ||
ref: isSelected ? ref : undefined, | ||
tabIndex: isFocused ? 0 : -1, | ||
onFocus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onFocus: isSelected ? onFocus: undefined
Would this work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, but then it does not catch programmatically focusing elements within a cell.
Then again we don't change the cell selection when we programmatically focus something within cells.
Extracted from #2459