Repository navigation
fix: cancel pending autoFocus raf when dropdown closes - #276
Open
mokshupadhyay wants to merge 1 commit into
Open
mokshupadhyay wants to merge 1 commit into
mokshupadhyay wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough自动聚焦效果现在保存动画帧任务 ID,并在清理时取消已排定的任务。新增测试验证自动聚焦后关闭时,触发元素仍保持焦点。 Changes自动聚焦任务清理
Estimated code review effort: 2 (Simple) | ~8 minutes Change: Bug fix Suggested reviewers: Merge Risk:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
autoFocus,useAccessibilityschedules the focus of the menu withraf(() => focusMenu(...), 3), which runs three animation frames after the dropdown opens. The cleanup of that effect removed thekeydownlistener but did not cancel the pendingraf. So if the dropdown closed before those frames passed (for example it is opened and closed quickly, oropenis toggled by the parent), the scheduled callback still ran afterwards and moved focus into the menu that was no longer open, away from the trigger.The effect now keeps the id returned by
raf()and callsraf.cancel(rafId)in its cleanup, so a close before the callback fires cancels the focus. Behaviour when the dropdown stays open is unchanged (the menu is still focused after the three frames).Test:
cancels pending autoFocus when closed before raf firesintests/useAccessibility.test.tsxrenders the hook withopen: trueandautoFocus, re-renders withopen: false, runs all timers and expects focus to stay on the trigger. It fails onmaster(focus ends up elsewhere, on the menu) and passes now.npx rc-testpasses (6 suites, 32 tests),tsc --noEmitand ESLint on the hook are clean, and Prettier is clean on the changed files.Summary by CodeRabbit
Bug 修复
测试