Skip to content

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

Merged
merged 4 commits into from
Apr 7, 2022
Merged

Refactor useRovingCellRef, fix test warnings #2883

merged 4 commits into from
Apr 7, 2022

Conversation

nstepien
Copy link
Contributor

@nstepien nstepien commented Apr 7, 2022

Extracted from #2459

@nstepien nstepien requested a review from amanmahajan7 as a code owner April 7, 2022 09:29
@nstepien nstepien self-assigned this Apr 7, 2022
@codecov
Copy link

codecov bot commented Apr 7, 2022

Codecov Report

Merging #2883 (a07b3ed) into main (625fad5) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head a07b3ed differs from pull request most recent head 3763416. Consider uploading reports for the commit 3763416 to get more accurate results

@@            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              
Impacted Files Coverage Δ
src/hooks/useRovingCellRef.ts 100.00% <100.00%> (ø)

@nstepien nstepien enabled auto-merge (squash) April 7, 2022 09:40
(cell: HTMLDivElement | null) => {
if (cell === null || !isSelected || cell.contains(document.activeElement)) return;

cell.focus({ preventScroll: true });
Copy link
Contributor

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

Copy link
Contributor Author

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.


return {
ref,
ref: isSelected ? ref : undefined,
tabIndex: isFocused ? 0 : -1,
onFocus
Copy link
Contributor

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?

Copy link
Contributor Author

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.

amanmahajan7
amanmahajan7 previously approved these changes Apr 7, 2022
@amanmahajan7 amanmahajan7 disabled auto-merge April 7, 2022 14:42
@nstepien nstepien merged commit 2b402e8 into main Apr 7, 2022
@nstepien nstepien deleted the rover branch April 7, 2022 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants