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}
|
* @type {HTMLElement}
|
||||||
*/
|
*/
|
||||||
get contentWrapperNode() {
|
get contentWrapperNode() {
|
||||||
return /** @type {HTMLElement} */ (this.__contentWrapperNode ||
|
return /** @type {HTMLElement} */ (
|
||||||
this.config?.contentWrapperNode);
|
this.__contentWrapperNode || this.config?.contentWrapperNode
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -262,8 +263,9 @@ export class OverlayController extends EventTargetShim {
|
||||||
* @type {HTMLElement}
|
* @type {HTMLElement}
|
||||||
*/
|
*/
|
||||||
get elementToFocusAfterHide() {
|
get elementToFocusAfterHide() {
|
||||||
return /** @type {HTMLElement} */ (this.__elementToFocusAfterHide ||
|
return /** @type {HTMLElement} */ (
|
||||||
this.config?.elementToFocusAfterHide);
|
this.__elementToFocusAfterHide || this.config?.elementToFocusAfterHide
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -588,8 +590,9 @@ export class OverlayController extends EventTargetShim {
|
||||||
if (this.__isContentNodeProjected && this.contentWrapperNode.isConnected) {
|
if (this.__isContentNodeProjected && this.contentWrapperNode.isConnected) {
|
||||||
// We need to keep track of the original local context.
|
// We need to keep track of the original local context.
|
||||||
/** config [l2], [l4] */
|
/** config [l2], [l4] */
|
||||||
this.__originalContentParent = /** @type {HTMLElement} */ (this.contentWrapperNode
|
this.__originalContentParent = /** @type {HTMLElement} */ (
|
||||||
.parentNode);
|
this.contentWrapperNode.parentNode
|
||||||
|
);
|
||||||
} else if (cfgToAdd.contentNode && cfgToAdd.contentNode.isConnected) {
|
} else if (cfgToAdd.contentNode && cfgToAdd.contentNode.isConnected) {
|
||||||
// We need to keep track of the original local context.
|
// We need to keep track of the original local context.
|
||||||
/** config [l1], [l3], [g1] */
|
/** config [l1], [l3], [g1] */
|
||||||
|
|
@ -905,15 +908,16 @@ export class OverlayController extends EventTargetShim {
|
||||||
|
|
||||||
/** @protected */
|
/** @protected */
|
||||||
_restoreFocus() {
|
_restoreFocus() {
|
||||||
const { activeElement } = /** @type {* & ShadowRoot} */ (this
|
const { activeElement } = /** @type {* & ShadowRoot} */ (
|
||||||
.__contentWrapperNode).getRootNode();
|
this.__contentWrapperNode
|
||||||
|
).getRootNode();
|
||||||
// We only are allowed to move focus if we (still) 'own' it.
|
// We only are allowed to move focus if we (still) 'own' it.
|
||||||
// Otherwise we assume the 'outside world' has, purposefully, taken over
|
// Otherwise we assume the 'outside world' has, purposefully, taken over
|
||||||
if (
|
if (
|
||||||
activeElement &&
|
activeElement &&
|
||||||
/** @type {HTMLElement} */ (this.__contentWrapperNode).contains(activeElement)
|
/** @type {HTMLElement} */ (this.__contentWrapperNode).contains(activeElement)
|
||||||
) {
|
) {
|
||||||
if (this.elementToFocusAfterHide) {
|
if (this.elementToFocusAfterHide instanceof HTMLElement) {
|
||||||
this.elementToFocusAfterHide.focus();
|
this.elementToFocusAfterHide.focus();
|
||||||
} else {
|
} else {
|
||||||
activeElement.blur();
|
activeElement.blur();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue