Skip to content

chore(Drawer): rely on FocusTrap returnFocus for focus restoration#1591

Merged
brtbrt merged 11 commits into
masterfrom
mbertamini/1589-unify-focus-restoration
Jun 30, 2026
Merged

chore(Drawer): rely on FocusTrap returnFocus for focus restoration#1591
brtbrt merged 11 commits into
masterfrom
mbertamini/1589-unify-focus-restoration

Conversation

@brtbrt

@brtbrt brtbrt commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Context

Follow-up from PR #1578, which changed FocusTrap's default to returnFocus = true. With that default, Drawer restored focus twice on close: once through FocusTrap (react-focus-lock's returnFocus) and once through its own useRestoreFocus hook. This produced redundant focus() calls.

Changes

  • Remove Drawer's useRestoreFocus hook and rely on FocusTrap's returnFocus as the single source of truth, matching Dialog and Sheet.
  • Add focus-restoration tests for Drawer and Sheet, which previously had none. Dialog was already covered.
  • Remove the resolved TODO in FocusTrap.

Audit notes

All four FocusTrap consumers were reviewed. Dialog, Sheet, and NavigationBar already relied on FocusTrap; only Drawer carried bespoke logic. NavigationBar is intentionally excluded: its FocusTrap wraps the bar including the burger trigger, so focus is retained on the trigger automatically and returnFocus performs no restoration there, leaving nothing meaningful to test.

Closes #1589

Copilot AI review requested due to automatic review settings June 26, 2026 13:02
@brtbrt brtbrt added the AI AI Generated label Jun 26, 2026
@brtbrt brtbrt requested a review from a team June 26, 2026 13:02
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown

Size stats

master this branch diff
Total JS 17 MB 17 MB -320 B
JS without icons 2.07 MB 2.07 MB -320 B
Lib overhead 96.3 kB 96.3 kB 0 B
Lib overhead (gzip) 21.1 kB 21.1 kB 0 B

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors Drawer focus handling to rely on FocusTrap’s returnFocus (now defaulting to true) as the single focus-restoration mechanism, aligning Drawer with other modal components and avoiding duplicate focus() calls on close.

Changes:

  • Removed Drawer’s bespoke useRestoreFocus unmount logic to avoid double focus restoration.
  • Removed the resolved TODO in FocusTrap related to unifying focus restoration.
  • Added focus-restoration tests for Sheet and Drawer.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/focus-trap.tsx Removes resolved TODO now that consumers are converging on returnFocus.
src/drawer.tsx Deletes useRestoreFocus so Drawer relies on FocusTrap for restoring focus.
src/__tests__/sheet-test.tsx Adds a regression test asserting focus returns to the trigger after closing a Sheet.
src/__tests__/drawer-test.tsx Adds a regression test asserting focus returns to the trigger after closing a Drawer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/__tests__/drawer-test.tsx
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown

Deploy preview for mistica-web ready!

Project:mistica-web
Status: ✅  Deploy successful!
Preview URL:https://mistica-15uwvrbwp-flows-projects-65bb050e.vercel.app
Latest Commit:a611305

Deployed with vercel-action

@brtbrt brtbrt changed the title refactor(Drawer): rely on FocusTrap returnFocus for focus restoration chore(Drawer): rely on FocusTrap returnFocus for focus restoration Jun 26, 2026
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown

Accessibility report
✔️ No issues found

ℹ️ You can run this locally by executing yarn audit-accessibility.

@brtbrt brtbrt force-pushed the mbertamini/1589-unify-focus-restoration branch from 25bec9f to e70fff3 Compare June 26, 2026 13:12
FocusTrap defaults to returnFocus = true, which restores focus to the
previously focused element when the trap unmounts. Drawer also restored
focus through its own useRestoreFocus hook, producing duplicate focus()
calls on close.

Remove Drawer's useRestoreFocus and rely solely on FocusTrap, matching
Dialog and Sheet. Add focus-restoration tests for Drawer and Sheet,
which previously had none, and drop the now-resolved TODO in FocusTrap.

Closes #1589
Copilot AI review requested due to automatic review settings June 26, 2026 13:16
@brtbrt brtbrt force-pushed the mbertamini/1589-unify-focus-restoration branch from e70fff3 to d69d384 Compare June 26, 2026 13:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

brtbrt added 2 commits June 26, 2026 15:33
Guide agents to read only the docs relevant to a task rather than all
docs upfront, and provide a tree-style map of the `doc` directory with a
one-line description of each entry.
(B
…sioning

Add doc/commits-and-prs.md covering conventional commits, the supported
type subset enforced by validate-pr-title, and the semantic-release flow.
Reference it from CONTRIBUTING.md and list both in the AGENTS.md doc map.
Copilot AI review requested due to automatic review settings June 26, 2026 13:52
Comment thread AGENTS.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread src/__tests__/drawer-test.tsx Outdated
Comment thread src/__tests__/sheet-test.tsx Outdated
Comment thread doc/commits-and-prs.md Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 26, 2026 23:40
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread AGENTS.md Outdated
@brtbrt

brtbrt commented Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

a11y report that http://localhost:6006/iframe.html?viewMode=story&id=components-accordions--accordion-story&skin=O2-new fails, but locally passes. do we have any known problem with CI?

Comment thread .github/actions/audit-accessibility/main.js
Comment thread doc/commits-and-prs.md Outdated
Comment thread doc/commits-and-prs.md Outdated
Comment thread doc/commits-and-prs.md Outdated
Comment thread doc/commits-and-prs.md Outdated
Comment thread AGENTS.md Outdated
Comment thread AGENTS.md Outdated
Comment thread .github/actions/audit-accessibility/main.js Outdated
@AlexandraGallipoliRodrigues

Copy link
Copy Markdown
Contributor

should the PR title be fix(Drawer): ... instead of chore(Drawer): ...?

…n up AGENTS doc map

Deletes doc/commits-and-prs.md and moves the PR title, description, and
reviewer rules inline into CONTRIBUTING. Simplifies AGENTS.md by removing
the documentation map section that pointed to the now-deleted file.
Copilot AI review requested due to automatic review settings June 29, 2026 17:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread CONTRIBUTING.md
Comment thread CONTRIBUTING.md
@brtbrt

brtbrt commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@AlexandraGallipoliRodrigues not really: this is not fixing up anything really, we're simply removing a duplicated behavior we have on a component :). but it's not causing any misbehavior

@brtbrt brtbrt requested review from a team and Marcosld June 29, 2026 18:02
Copilot AI review requested due to automatic review settings June 29, 2026 18:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread CONTRIBUTING.md
Comment thread AGENTS.md
---

## GitHub conventions
## Conventions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why rename?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because "github" can be misleading for the AI

Comment thread CONTRIBUTING.md
Comment thread CONTRIBUTING.md

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave the file as it was, we aren't really adding any info with these changes.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 30, 2026 13:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread CONTRIBUTING.md
Comment on lines +43 to +49
- fix
- feat
- chore
- revert
### PR Description
Concise summary of the problem and fix, ending with `Ref: <ISSUE-ID>`;

Comment on lines +76 to +79
await page.goto(url, {waitUntil: 'networkidle0'});
// Wait until the story has actually mounted, otherwise axe may scan the Storybook
// loading shell instead of the rendered story, producing flaky page-level results.
await page
@brtbrt brtbrt added this pull request to the merge queue Jun 30, 2026
Merged via the queue into master with commit 5dd0b77 Jun 30, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI AI Generated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify focus-restoration logic in FocusTrap and its consumers

4 participants