Fix popover focus return on tab navigation#5003
Draft
adamint wants to merge 1 commit into
Draft
Conversation
Contributor
There was a problem hiding this comment.
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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes keyboard focus behavior when tabbing out of anchored/popup UI:
FluentPopoverkeyboard navigation by finding a focusable anchor descendant, and skips the closing popup when moving focus to the next page element.FluentDataGridcolumn width popup when focus leaves it viaTab/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:
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~DataGridThe filtered test run passed: 52 tests, 0 failures.