Focus accordion toggle before clearing dismiss success notice - #1794
Conversation
Moves focus to the PanelBody toggle button before unmounting the Notice so keyboard users are not left with lost focus when the notice is dismissed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesFocus management in DismissPanel
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a useRef hook in DismissPanel to reference the panel element and focus the panel's toggle button when the success notice is dismissed. The reviewer suggests making the DOM query more robust by adding a fallback to a generic button selector, as relying solely on the internal WordPress component class .components-panel__body-toggle could be brittle if class names change in future updates.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Summary
useRefon the outerDismissPanelwrapper divonRemove), focuses thePanelBodytoggle button (.components-panel__body-toggle) before clearing the notice state, so focus moves to a live element before the notice's close button is unmountedWhy focus first, then clear?
The notice's dismiss button is about to be removed from the DOM. If we cleared state first, React would unmount the button while it still has focus — the browser then tries to recover focus, usually landing on
<body>. By focusing the toggle button first (still in the DOM), the transition is seamless and no focus loss occurs.Test plan
<body>or the modal backdrop🤖 Generated with Claude Code
Summary by CodeRabbit