Skip to content

PopoverPrimitive - Add onFocusOut argument#3571

Merged
dchyun merged 8 commits intomainfrom
dchyun/popover-primitive-focus-out
Mar 3, 2026
Merged

PopoverPrimitive - Add onFocusOut argument#3571
dchyun merged 8 commits intomainfrom
dchyun/popover-primitive-focus-out

Conversation

@dchyun
Copy link
Contributor

@dchyun dchyun commented Feb 9, 2026

📌 Summary

If merged, this PR would add a onFocusOut argument to the PopoverPrimitive and add it as well to the following components which use the PopoverPrimitive.

  • Dropdown
  • FilterBar
    • ActionsDropdown
    • FiltersDropdown
  • RichTooltip

PopoverPrimitive demo
FilterBar demo

🛠️ Detailed description

Originally raised in an instance of the FilterBar, it was observed that if the content of a PopoverPrimitive has content that changes dynamically, there are certain situations where the popover is closing automatically when the content changes, even if that is not the desired behavior.

The cause of this issue is related to when the element that is focused is removed from the DOM. When this occurs currently the PopoverPrimitive's onFocusOut action is called, and the popover is automatically closed if focus is not inside the popover. This existing behavior causes two issues.

  • The popover could close when it is not intended to do so
  • The document focus is lost, as the element with focus is removed and the popover is closed without the focus moving anywhere else.

To solve this issue an onFocusOut argument has been added to the PopoverPrimitive. When present, if the focus leaves the popover (which would occur if the element with focus is removed), the consumer can use the callback to direct the focus to another element in the popover and the popover is not closed. If focus moves out of the popover to another element on the page the popover is still closed automatically as is the case currently.

This argument has been additionally added to other components that use the PopoverPrimitive.

Native PopoverAPI

The PopoverPrimitive uses the native Popover API to display the content. The API does not close all popovers automatically when focus is lost. There could be situations for a11y purposes where the popover should remain open on focus loss, or situations where it should close. Our PopoverPrimitive is built to always close on focus out, so to continue that behavior this argument is needed for the use cases when the popover should not close on focus out. The Popover api does not provide any native callback that can be used to handle how focus is lost.

📸 Screenshots

PopoverPrimitive

Before

  • Clicking the "hide extra content" button removes that button from the DOM
  • Focus is lost, moves outside the popover, and the popover is closed automatically
Screen.Recording.2026-02-09.at.11.29.49.AM.mov

After

  • Clicking the "hide extra content" button removes that button from the DOM
  • Focus is lost, the onFocusOut callback is triggered in the PopoverPrimitive
  • The consumer has the callback set focus on the previous button, the popover remains open
Screen.Recording.2026-02-09.at.11.28.39.AM.mov

FilterBar

Before

Screen.Recording.2026-02-09.at.11.32.50.AM.mov

After

Screen.Recording.2026-02-09.at.11.31.03.AM.mov

🔗 External links

Jira ticket: HDS-5997
Figma file: [if it applies]


👀 Component checklist

💬 Please consider using conventional comments when reviewing this PR.

📋 PCI review checklist
  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.
  • If applicable, I've worked with GRC to document the impact of any changes to security controls.
    Examples of changes to controls include access controls, encryption, logging, etc.
  • If applicable, I've worked with GRC to ensure compliance due to a significant change to the in-scope PCI environment.
    Examples include changes to operating systems, ports, protocols, services, cryptography-related components, PII processing code, etc.

@vercel
Copy link

vercel bot commented Feb 9, 2026

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

Project Deployment Actions Updated (UTC)
hds-showcase Ready Ready Preview Mar 3, 2026 2:40pm
hds-website Ready Ready Preview Mar 3, 2026 2:40pm

Request Review

@alex-ju
Copy link
Member

alex-ju commented Feb 13, 2026

@dchyun you may already be aware, but this PR will likely need a rebase or redo after #3600

@dchyun
Copy link
Contributor Author

dchyun commented Feb 13, 2026

@dchyun you may already be aware, but this PR will likely need a rebase or redo after #3600

@alex-ju yeah I saw that come in but thanks for the heads up. I added a note to redo this after that merges.

shleewhite
shleewhite previously approved these changes Mar 2, 2026
@dchyun dchyun merged commit 1b6faa7 into main Mar 3, 2026
25 of 27 checks passed
@dchyun dchyun deleted the dchyun/popover-primitive-focus-out branch March 3, 2026 15:28
@hashibot-hds hashibot-hds mentioned this pull request Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants