-
Notifications
You must be signed in to change notification settings - Fork 671
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
base: feature/26_2_popover_support_content_reading
Are you sure you want to change the base?
Changes from all commits
7c31784
f793e3c
8010fa2
a17511a
d9aa676
5f6187d
41c93ba
b81cd6d
cd436bd
be5e944
19cd3f5
42151cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -992,14 +992,22 @@ class Overlay< | |
| const $currentElement = $elements?.eq(i) ?? null; | ||
| const $reverseElement = $elements?.eq(elementsCount - i) ?? null; | ||
|
|
||
| // @ts-expect-error is should can get function as callback | ||
| if (!$first && $currentElement.is(selectors.tabbable)) { | ||
| $first = $currentElement; | ||
| if (!$first) { | ||
| // @ts-expect-error is should can get function as callback | ||
| const isCurrentTabbable = $currentElement?.is(selectors.tabbable); | ||
| const isCurrentNotOverlay = $currentElement?.get(0) !== this._$content?.get(0); | ||
| if (isCurrentTabbable && isCurrentNotOverlay) { | ||
| $first = $currentElement; | ||
| } | ||
| } | ||
|
|
||
| // @ts-expect-error is should can get function as callback | ||
| if (!$last && $reverseElement.is(selectors.tabbable)) { | ||
| $last = $reverseElement; | ||
| if (!$last) { | ||
| // @ts-expect-error is should can get function as callback | ||
| const isReverseTabbable = $reverseElement?.is(selectors.tabbable); | ||
| const isReverseNotOverlay = $reverseElement?.get(0) !== this._$content?.get(0); | ||
|
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. The same comment about selector |
||
| if (isReverseTabbable && isReverseNotOverlay) { | ||
| $last = $reverseElement; | ||
| } | ||
| } | ||
|
|
||
| if ($first && $last) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,8 @@ export interface PopoverProperties extends Omit<Properties, | |
| _overlayContentRole?: string; | ||
|
|
||
| _describeTarget?: boolean; | ||
|
|
||
| _preventDialogFocus?: boolean; | ||
|
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. How about _preventDialogContainerFocus? |
||
| } | ||
| class Popover< | ||
| TProperties extends PopoverProperties = PopoverProperties, | ||
|
|
@@ -265,6 +267,48 @@ class Popover< | |
| _syncAriaAttributes(): void { | ||
| this.setAria('role', this._getEffectiveAriaRole()); | ||
| this._syncTargetAriaDescription(); | ||
| this._syncFocusOptions(); | ||
| } | ||
|
|
||
| _syncFocusOptions(): void { | ||
| if (this._getEffectiveAriaRole() === 'dialog' && !this.option('_preventDialogFocus')) { | ||
| 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; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| _focusTarget(): dxElementWrapper { | ||
| return this._getFocusTarget() ?? this.$overlayContent(); | ||
| } | ||
|
|
||
| _restoreTargetFocus(): void { | ||
| const $targets = this._getAriaDescriptionTargets(); | ||
|
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. We can have only one target. We can apply changes from this comment. |
||
|
|
||
| if ($targets.length) { | ||
| // @ts-expect-error trigger should be typed on type 'EventsEngineType' | ||
| eventsEngine.trigger($targets.first(), 'focus'); | ||
| } | ||
| } | ||
|
|
||
| _forceFocusLost(): void { | ||
|
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. Please check base method. May we can move there this logic. |
||
| if (this._getEffectiveAriaRole() === 'dialog') { | ||
| this._restoreTargetFocus(); | ||
| } else { | ||
| super._forceFocusLost(); | ||
| } | ||
| } | ||
|
|
||
| _getAriaRole(): string { | ||
|
|
@@ -894,6 +938,10 @@ class Popover< | |
| } | ||
|
|
||
| _dispose(): void { | ||
| const { visible } = this.option(); | ||
| if (visible && 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(); | ||
|
|
||
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.
Can we include overlay selector in the previous one:
?