mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-22 16:56:35 +00:00
Restore focus when returning to tab (#6276)
This commit is contained in:
parent
71faaf2ab1
commit
43fbf97e10
8
src/common/dom/deep-active-element.ts
Normal file
8
src/common/dom/deep-active-element.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export const deepActiveElement = (
|
||||
root: DocumentOrShadowRoot = document
|
||||
): Element | null => {
|
||||
if (root.activeElement?.shadowRoot?.activeElement) {
|
||||
return deepActiveElement(root.activeElement.shadowRoot);
|
||||
}
|
||||
return root.activeElement;
|
||||
};
|
@ -14,6 +14,7 @@ import {
|
||||
STATE_RUNNING,
|
||||
} from "home-assistant-js-websocket";
|
||||
import { CustomPanelInfo } from "../data/panel_custom";
|
||||
import { deepActiveElement } from "../common/dom/deep-active-element";
|
||||
|
||||
const CACHE_URL_PATHS = ["lovelace", "developer-tools"];
|
||||
const COMPONENTS = {
|
||||
@ -92,7 +93,9 @@ class PartialPanelResolver extends HassRouterPage {
|
||||
|
||||
private _waitForStart = false;
|
||||
|
||||
private _disconnectedPanel?: ChildNode;
|
||||
private _disconnectedPanel?: HTMLElement;
|
||||
|
||||
private _disconnectedActiveElement?: HTMLElement;
|
||||
|
||||
private _hiddenTimeout?: number;
|
||||
|
||||
@ -185,7 +188,13 @@ class PartialPanelResolver extends HassRouterPage {
|
||||
!(curPanel.config as CustomPanelInfo).config._panel_custom
|
||||
.embed_iframe)
|
||||
) {
|
||||
this._disconnectedPanel = this.lastChild;
|
||||
this._disconnectedPanel = this.lastChild as HTMLElement;
|
||||
const activeEl = deepActiveElement(
|
||||
this._disconnectedPanel.shadowRoot || undefined
|
||||
);
|
||||
if (activeEl instanceof HTMLElement) {
|
||||
this._disconnectedActiveElement = activeEl;
|
||||
}
|
||||
this.removeChild(this.lastChild);
|
||||
}
|
||||
}, 300000);
|
||||
@ -201,6 +210,10 @@ class PartialPanelResolver extends HassRouterPage {
|
||||
this.appendChild(this._disconnectedPanel);
|
||||
this._disconnectedPanel = undefined;
|
||||
}
|
||||
if (this._disconnectedActiveElement) {
|
||||
this._disconnectedActiveElement.focus();
|
||||
this._disconnectedActiveElement = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
private async _updateRoutes(oldPanels?: HomeAssistant["panels"]) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user