-
Notifications
You must be signed in to change notification settings - Fork 672
Popover: focus management for dialog role #34413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dmlvr
merged 19 commits into
DevExpress:feature/26_2_popover_support_content_reading
from
dmlvr:dmlvr-feature/26_2_popover_support_content_reading
Jul 29, 2026
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7c31784
add some more popover tests
dmlvr f793e3c
move and return focus for dialog role
dmlvr 8010fa2
Merge remote-tracking branch 'upstream/feature/26_2_popover_support_c…
dmlvr a17511a
fix after merging
dmlvr d9aa676
update _syncFocusOptions
dmlvr 5f6187d
refactoring
dmlvr 41c93ba
fix by review comment
dmlvr b81cd6d
update tabindex for overlay
dmlvr cd436bd
add internal Option to prevent focus management for dialog role (Look…
dmlvr be5e944
return focus management in Popover
dmlvr 19cd3f5
leftovers
dmlvr 42151cd
fix for appointment tooltip integration
dmlvr a4e8d51
fix after review
dmlvr a29cb52
fix notexpected behavior
dmlvr c76bcc7
fix _findTabbableBounds
dmlvr 6322577
leftovers
dmlvr ac47eaa
Merge branch 'feature/26_2_popover_support_content_reading' into dmlv…
dmlvr 3f152f7
linter
dmlvr 3e348eb
Merge branch 'dmlvr-feature/26_2_popover_support_content_reading' of …
dmlvr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,8 @@ export interface PopoverProperties extends Omit<Properties, | |
| _overlayContentRole?: string; | ||
|
|
||
| _describeTarget?: boolean; | ||
|
|
||
| _preventDialogContainerFocus?: boolean; | ||
| } | ||
| class Popover< | ||
| TProperties extends PopoverProperties = PopoverProperties, | ||
|
|
@@ -266,6 +268,57 @@ class Popover< | |
| _syncAriaAttributes(): void { | ||
| this.setAria('role', this._getEffectiveAriaRole()); | ||
| this._syncTargetAriaDescription(); | ||
| this._syncFocusOptions(); | ||
| } | ||
|
|
||
| _syncFocusOptions(): void { | ||
| if (this._getEffectiveAriaRole() === 'dialog' && !this.option('_preventDialogContainerFocus')) { | ||
| this._setOptionWithoutOptionChange('focusStateEnabled', true); | ||
| this._setOptionWithoutOptionChange('tabFocusLoopEnabled', true); | ||
| } | ||
| } | ||
|
|
||
| // Intentional no-op: Focus target logic is inherited from Widget, | ||
| // uses in Popup and do not need here. | ||
| _renderFocusTarget(): void {} | ||
|
|
||
| _getFocusTarget(): dxElementWrapper | null | undefined { | ||
| const $firstFocusableTarget = this._findTabbableBounds().$first; | ||
| if ($firstFocusableTarget?.length) { | ||
| return $firstFocusableTarget; | ||
| } | ||
|
|
||
| const $overlay = this.$overlayContent(); | ||
| if ($overlay?.length) { | ||
| if ($overlay.attr('tabindex') !== '-1') { | ||
| $overlay.attr('tabindex', '-1'); | ||
| } | ||
| return $overlay; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| _focusTarget(): dxElementWrapper { | ||
| return this._getFocusTarget() ?? this.$overlayContent(); | ||
| } | ||
|
|
||
| _restoreTargetFocus(): void { | ||
| const $target = this._getAriaDescriptionTargets(); | ||
| const targetElement = $target.first().get(0); | ||
|
|
||
| if (targetElement && domAdapter.getBody().contains(targetElement)) { | ||
| // @ts-expect-error trigger should be typed on type 'EventsEngineType' | ||
| eventsEngine.trigger($target.first(), 'focus'); | ||
| } | ||
| } | ||
|
|
||
| _forceFocusLost(): void { | ||
| if (this._getEffectiveAriaRole() === 'dialog') { | ||
| this._restoreTargetFocus(); | ||
| } else { | ||
| super._forceFocusLost(); | ||
| } | ||
| } | ||
|
|
||
| protected _getAriaRole(): string { | ||
|
|
@@ -295,10 +348,15 @@ class Popover< | |
|
|
||
| _ensurePopoverContentId(): string { | ||
| const $overlayContent = this.$overlayContent(); | ||
| this._popoverContentId = this._popoverContentId | ||
| ?? $overlayContent.attr('id') | ||
| ?? `dx-${new Guid()}`; | ||
| this.setAria('id', this._popoverContentId, $overlayContent); | ||
| const existingId = $overlayContent.attr('id'); | ||
|
|
||
| if (existingId) { | ||
| this._popoverContentId = existingId; | ||
| return existingId; | ||
| } | ||
|
|
||
| this._popoverContentId = this._popoverContentId ?? `dx-${new Guid()}`; | ||
| $overlayContent.attr('id', this._popoverContentId); | ||
|
|
||
| return this._popoverContentId; | ||
| } | ||
|
|
@@ -479,7 +537,7 @@ class Popover< | |
| _detachHoverableOverlay(): void { | ||
| const $overlayContent = this.$overlayContent(); | ||
|
|
||
| if (!$overlayContent.length) { | ||
| if (!$overlayContent?.length) { | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -882,14 +940,31 @@ class Popover< | |
| _clean(): void { | ||
| const { target } = this.option(); | ||
|
|
||
| const $overlayContent = this.$overlayContent(); | ||
| if ($overlayContent?.length) { | ||
| const existingId = $overlayContent.attr('id'); | ||
| if (existingId) { | ||
| this._popoverContentId = existingId; | ||
| } | ||
| } | ||
|
|
||
| this._detachEscapeKeyHandler(); | ||
| this._detachEvents(target); | ||
| this._detachHoverableOverlay(); | ||
|
|
||
| super._clean(); | ||
| } | ||
|
|
||
| _shouldResetActiveElement(): boolean { | ||
| const activeElement = domAdapter.getActiveElement(); | ||
| return domAdapter.isNode(activeElement) && !!this._$content?.get(0)?.contains(activeElement); | ||
| } | ||
|
|
||
| _dispose(): void { | ||
| const { visible } = this.option(); | ||
| if (visible && this._shouldResetActiveElement() && this._getEffectiveAriaRole() === 'dialog') { | ||
| this._restoreTargetFocus(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we check if we have focus inside? |
||
| } | ||
| this._removeTargetAriaDescription(); | ||
| this._detachEscapeKeyHandler(); | ||
| super._dispose(); | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check base method. May we can move there this logic.
Also please check what exactly base method do and why.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The base
Overlay._forceFocusLost()checks if the currently focused element is inside the overlay content (this._$content) and blurs (resets) it if so. This prevents focus from being trapped on hidden/invisible elements when the overlay closes, which would break keyboard navigation.No. The base
Overlayclass lacks the role-awareness (_getEffectiveAriaRole()) and target resolution mechanics (_getAriaDescriptionTargets()) thatPopoveruses to identify and refocus its trigger element.