fix(overlays): only use elementToFocusAfterHide when provided as HTMLElement
This commit is contained in:
parent
675f7b1cdd
commit
f76f4b36b0
2 changed files with 18 additions and 9 deletions
5
.changeset/moody-ways-tap.md
Normal file
5
.changeset/moody-ways-tap.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@lion/overlays': patch
|
||||
---
|
||||
|
||||
fix: only use elementToFocusAfterHide when provided as HTMLElement
|
||||
|
|
@ -244,8 +244,9 @@ export class OverlayController extends EventTargetShim {
|
|||
* @type {HTMLElement}
|
||||
*/
|
||||
get contentWrapperNode() {
|
||||
return /** @type {HTMLElement} */ (this.__contentWrapperNode ||
|
||||
this.config?.contentWrapperNode);
|
||||
return /** @type {HTMLElement} */ (
|
||||
this.__contentWrapperNode || this.config?.contentWrapperNode
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -262,8 +263,9 @@ export class OverlayController extends EventTargetShim {
|
|||
* @type {HTMLElement}
|
||||
*/
|
||||
get elementToFocusAfterHide() {
|
||||
return /** @type {HTMLElement} */ (this.__elementToFocusAfterHide ||
|
||||
this.config?.elementToFocusAfterHide);
|
||||
return /** @type {HTMLElement} */ (
|
||||
this.__elementToFocusAfterHide || this.config?.elementToFocusAfterHide
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -588,8 +590,9 @@ export class OverlayController extends EventTargetShim {
|
|||
if (this.__isContentNodeProjected && this.contentWrapperNode.isConnected) {
|
||||
// We need to keep track of the original local context.
|
||||
/** config [l2], [l4] */
|
||||
this.__originalContentParent = /** @type {HTMLElement} */ (this.contentWrapperNode
|
||||
.parentNode);
|
||||
this.__originalContentParent = /** @type {HTMLElement} */ (
|
||||
this.contentWrapperNode.parentNode
|
||||
);
|
||||
} else if (cfgToAdd.contentNode && cfgToAdd.contentNode.isConnected) {
|
||||
// We need to keep track of the original local context.
|
||||
/** config [l1], [l3], [g1] */
|
||||
|
|
@ -905,15 +908,16 @@ export class OverlayController extends EventTargetShim {
|
|||
|
||||
/** @protected */
|
||||
_restoreFocus() {
|
||||
const { activeElement } = /** @type {* & ShadowRoot} */ (this
|
||||
.__contentWrapperNode).getRootNode();
|
||||
const { activeElement } = /** @type {* & ShadowRoot} */ (
|
||||
this.__contentWrapperNode
|
||||
).getRootNode();
|
||||
// We only are allowed to move focus if we (still) 'own' it.
|
||||
// Otherwise we assume the 'outside world' has, purposefully, taken over
|
||||
if (
|
||||
activeElement &&
|
||||
/** @type {HTMLElement} */ (this.__contentWrapperNode).contains(activeElement)
|
||||
) {
|
||||
if (this.elementToFocusAfterHide) {
|
||||
if (this.elementToFocusAfterHide instanceof HTMLElement) {
|
||||
this.elementToFocusAfterHide.focus();
|
||||
} else {
|
||||
activeElement.blur();
|
||||
|
|
|
|||
Loading…
Reference in a new issue