Skip to content

Fix popover focus return on tab navigation#5003

Draft
adamint wants to merge 1 commit into
microsoft:devfrom
adamint:adamint/fix-popover-focus-return
Draft

Fix popover focus return on tab navigation#5003
adamint wants to merge 1 commit into
microsoft:devfrom
adamint:adamint/fix-popover-focus-return

Conversation

@adamint

@adamint adamint commented Jul 9, 2026

Copy link
Copy Markdown
Member

Summary

Fixes keyboard focus behavior when tabbing out of anchored/popup UI:

  • Resolves non-focusable composite anchors in FluentPopover keyboard navigation by finding a focusable anchor descendant, and skips the closing popup when moving focus to the next page element.
  • Closes the FluentDataGrid column width popup when focus leaves it via Tab / Shift+Tab, preserving the expected previous/next focus target.

Fixes #5001
Fixes #5002

Proof

I verified the two reported downstream repros with a temporary browser harness importing these edited JS modules directly:

overflow Shift+Tab returns to inner MoreButtonTemplate trigger: pass
overflow Tab skips closing popover and moves after trigger: pass
DataGrid Shift+Tab closes resize popup and returns to header: pass
DataGrid Tab closes resize popup and advances to next header: pass

I also ran:

node --check src/Core/Components/AnchoredRegion/FluentAnchoredRegion.razor.js
node --check src/Core/Components/DataGrid/FluentDataGrid.razor.js
dotnet test tests/Core/Microsoft.FluentUI.AspNetCore.Components.Tests.csproj --no-build --filter FullyQualifiedName~DataGrid

The filtered test run passed: 52 tests, 0 failures.

Copilot AI review requested due to automatic review settings July 9, 2026 03:08

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

This PR fixes keyboard focus behavior when tabbing out of popover/popup-style UI in Fluent UI Blazor, addressing downstream accessibility and usability issues reported for FluentPopover (anchored-region keyboard traversal) and FluentDataGrid (column resize popup).

Changes:

  • Update anchored-region keyboard navigation to resolve focusable descendants for composite/non-focusable anchors and avoid wrapping traversal to the first document focusable.
  • Add Tab/Shift+Tab boundary handling to close the DataGrid column resize popup when focus leaves via keyboard navigation.
Show a summary per file
File Description
src/Core/Components/AnchoredRegion/FluentAnchoredRegion.razor.js Improves anchor/popup keyboard navigation by resolving focus targets and refining “next focus after anchor” logic.
src/Core/Components/DataGrid/FluentDataGrid.razor.js Adds keyboard Tab boundary handling for the column resize popup, including focus-target selection on close.

Review details

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 4
  • Review effort level: Low

Comment on lines 129 to 136
ev.stopPropagation();
if (!ev.shiftKey) {
// Case 3: move to element after anchor in page
let startFrom;
if (anchorElement.tagName.startsWith("FLUENT-") && anchorElement.shadowRoot?.children.length > 0) {
startFrom = anchorElement.shadowRoot.children[0];
} else {
startFrom = anchorElement;
}
new FocusableElement(anchorElement.getRootNode()).findNextFocusableElement(startFrom)?.focus();
findNextFocusableElementAfterAnchor(anchorElement, popupElement)?.focus();
} else {
// Case 2: Shift+Tab → focus anchor
anchorElement.focus();
getAnchorFocusTarget(anchorElement).focus();
}
Comment on lines +62 to +69
function getFluentShadowFocusTarget(element) {
if (!element?.tagName?.startsWith("FLUENT-")) {
return null;
}

return Array.from(element.shadowRoot?.children ?? [])
.find(child => child.tabIndex !== -1 && child.checkVisibility()) ?? null;
}
Comment on lines +107 to +113
const resizeFocusables = getFocusableElements(columnResizeElement);
const activeIndex = resizeFocusables.indexOf(document.activeElement);
const isFirstElement = activeIndex === 0;
const isLastElement = activeIndex === resizeFocusables.length - 1;

if ((event.shiftKey && isFirstElement) || (!event.shiftKey && isLastElement)) {
const focusTarget = findAdjacentFocusableElement(document.activeElement, event.shiftKey);
Comment on lines +71 to +79
function findNextFocusableElementAfterAnchor(anchorElement, popupElement) {
const startFrom = getAnchorTraversalStart(anchorElement);
const focusableElements = new FocusableElement(anchorElement.getRootNode())
.getFocusableElements()
.filter(element => !popupElement.contains(element));
const currentIndex = focusableElements.indexOf(startFrom);

return currentIndex === -1 ? null : focusableElements[currentIndex + 1] ?? null;
}
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.

FluentDataGrid column width popup stays open after tabbing out FluentOverflow MoreButtonTemplate popover loses focus return on Tab/Shift+Tab

2 participants