Skip to content

fix(focus): add ignoreElement support and update deps (#557)#572

Merged
zombieJ merged 1 commit intomasterfrom
fix-focus
Feb 6, 2026
Merged

fix(focus): add ignoreElement support and update deps (#557)#572
zombieJ merged 1 commit intomasterfrom
fix-focus

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Feb 6, 2026

  • Update @rc-component/util to 1.9.0
  • Add ignoreElement to handle focus elements from Portal
  • Add onClose and onFocus type to DrawerPanelEvents
  • Add test case for focus handling with Portal

ref ant-design/ant-design#56782

- Update @rc-component/util to 1.9.0
- Add ignoreElement to handle focus elements from Portal
- Add onClose and onFocus type to DrawerPanelEvents
- Add test case for focus handling with Portal

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Feb 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
drawer Ready Ready Preview, Comment Feb 6, 2026 8:35am

@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

Warning

Rate limit exceeded

@zombieJ has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 45 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-focus

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @zombieJ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the focus management within the Drawer component, particularly when dealing with interactive elements rendered via React Portals. It ensures that elements outside the main DOM hierarchy of the drawer can be correctly focused without being inadvertently trapped by the drawer's focus lock. This enhancement provides a more robust and accessible user experience, alongside a routine update to a core utility library.

Highlights

  • Dependency Update: Updated the @rc-component/util dependency to version 1.9.0.
  • Focus Management for Portals: Implemented ignoreElement support within the useFocusable hook to correctly handle focus for elements rendered inside React Portals, preventing unintended focus trapping.
  • Drawer Panel Events: Added an onFocus event type to the DrawerPanelEvents interface, allowing for focus event handling directly on the drawer panel.
  • New Test Case: Introduced a new test case to specifically verify that ignoreElement is correctly invoked when an element within a Portal inside the Drawer receives focus.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • package.json
    • Updated @rc-component/util dependency from ^1.7.0 to ^1.9.0.
  • src/DrawerPanel.tsx
    • Added onFocus?: React.FocusEventHandler<HTMLDivElement>; to the DrawerPanelEvents interface.
  • src/DrawerPopup.tsx
    • Modified the useFocusable hook call to capture the returned ignoreElement function.
    • Implemented an onFocus handler for the DrawerPanel to invoke ignoreElement with the focused target, ensuring elements within Portals are properly handled by the focus trap.
  • src/hooks/useFocusable.ts
    • Changed the useFocusable hook to return the ignoreElement function provided by useLockFocus, making it available for external use.
  • tests/focus.spec.tsx
    • Added a new test file (tests/focus.spec.tsx) to include a test case that verifies ignoreElement is called when an input element within a React Portal inside the Drawer is focused.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7e80e43) to head (ef90b3f).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #572   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines          205       209    +4     
  Branches        75        75           
=========================================
+ Hits           205       209    +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates @rc-component/util and leverages the new ignoreElement function from useLockFocus to correctly handle focus within Portals in the Drawer component. A new test case is added to verify this behavior. The changes look good and address the intended issue. I've added a few suggestions: one to prevent a potential runtime error by adding a type check, and a couple of others to improve the quality and robustness of the new test file.

Comment on lines +314 to +316
onFocus: (e: React.FocusEvent<HTMLDivElement>) => {
ignoreElement(e.target);
},
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The e.target of a focus event is of type EventTarget, which is not assignable to the HTMLElement type expected by ignoreElement. This could lead to runtime errors. It's safer to add a type check to ensure e.target is an HTMLElement before passing it to ignoreElement.

    onFocus: (e: React.FocusEvent<HTMLDivElement>) => {
      if (e.target instanceof HTMLElement) {
        ignoreElement(e.target);
      }
    },

Comment on lines +12 to +20
const hooks = actual.useLockFocus(visible, ...rest);
const hooksArray = Array.isArray(hooks) ? hooks : [hooks];
const proxyIgnoreElement = (ele: HTMLElement) => {
(globalThis as any).__ignoredElement = ele;
hooksArray[0](ele);
};
return [proxyIgnoreElement, ...hooksArray.slice(1)] as ReturnType<
typeof actual.useLockFocus
>;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The implementation of the mocked useLockFocus can be simplified. Since @rc-component/util@1.9.0's useLockFocus is guaranteed to return a tuple [ignore, restore], you can use array destructuring directly instead of the defensive Array.isArray check. This makes the mock cleaner and easier to understand.

    const [ignore, ...otherHooks] = actual.useLockFocus(visible, ...rest);
    const proxyIgnoreElement = (ele: HTMLElement) => {
      (globalThis as any).__ignoredElement = ele;
      ignore(ele);
    };
    return [proxyIgnoreElement, ...otherHooks] as ReturnType<
      typeof actual.useLockFocus
    >;

Comment on lines +34 to +37
afterEach(() => {
jest.useRealTimers();
cleanup();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The mock for useLockFocus sets properties on globalThis for testing purposes. It's a good practice to clean up these global properties in an afterEach block to avoid test pollution, where state from one test can leak into and affect subsequent tests.

  afterEach(() => {
    jest.useRealTimers();
    cleanup();
    delete (globalThis as any).__ignoredElement;
    delete (globalThis as any).__useLockFocusVisible;
  });

@zombieJ zombieJ merged commit 1d52932 into master Feb 6, 2026
13 checks passed
@zombieJ zombieJ deleted the fix-focus branch February 6, 2026 08:38
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.

1 participant