fix: #8686 prevent useGridCell from overriding child focus restoration loops#10228
fix: #8686 prevent useGridCell from overriding child focus restoration loops#10228jsmitrah wants to merge 5 commits into
Conversation
snowystinger
left a comment
There was a problem hiding this comment.
Thanks for the interest, if you run yarn format it should get rid of all the noisy whitespace changes that I'm guessing your IDE applied
0a7cf3b to
714723c
Compare
|
Thanks @snowystinger, all tests are passed |
ccb8bbd to
4b28c4a
Compare
71950d3 to
22b6e5f
Compare
| return; | ||
| } | ||
|
|
||
| // If the cell itself is focused, wait a frame so that focus finishes propagatating |
There was a problem hiding this comment.
This seems like an important comment. JSDOM and the act environment is not a reliable test against this as it's simulating real browsers.
Did you run this against real browsers? If I recall, document.activeElement can be updated at different times depending on the browser you're in as well.
There was a problem hiding this comment.
Good catch, @snowystinger. To avoid the timing issues of the document.activeElement across different real browsers, I updated the approach to use e.relatedTarget.
By checking e.relatedTarget synchronously, we can instantly determine if focus is moving directly into a nested child element. This provides identical, reliable accuracy in both JSDOM and real browsers without needing to wait for a frame
I've pushed the update.
There was a problem hiding this comment.
I don't see any update with relatedTarget?
There was a problem hiding this comment.
Apologies for the confusion, @snowystinger . I initially tried an implementation using e.relatedTarget, but it completely broke the React 16 test suite (test-16) on CircleCI due to synthetic event pooling limitations in older environments.
Because asynchronous timeouts/frames break the synchronous act() testing clock, I reverted to the synchronous approach using getActiveElement(). I have also restored the original comment regarding focus propagation to keep the documentation clear.
b06221e to
adbba17
Compare
6ab9b4c to
bce1556
Compare
| // useSelectableItem only handles setting the focused key when | ||
| // the focused element is the gridcell itself. We also want to | ||
| // set the focused key when a child element receives focus. | ||
| // If focus is currently visible (e.g. the user is navigating with the keyboard), | ||
| // then skip this. We want to restore focus to the previously focused row/cell | ||
| // in that case since the table should act like a single tab stop. |
There was a problem hiding this comment.
"My apologies, @snowystinger! That was completely accidental during a refactor pass in my editor. I have fully restored the original comment block.
| return; | ||
| } | ||
|
|
||
| // If the cell itself is focused, wait a frame so that focus finishes propagatating |
There was a problem hiding this comment.
I don't see any update with relatedTarget?
535198e to
244fa42
Compare
244fa42 to
24667bf
Compare
Closes #8686
✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: