From 3fb2d2408c963fd6f897c5eacaa9cf9bf1b01dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Pereira=20Mu=C3=B1oz?= Date: Sat, 13 Jan 2024 15:23:00 +0100 Subject: [PATCH] Fix sidebar selection --- package.json | 2 +- src/custom-sidebar.ts | 15 ++++++++------- yarn.lock | 8 ++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index d4772e9..828ef78 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "typescript": "^5.3.3" }, "dependencies": { - "home-assistant-query-selector": "^4.1.0", + "home-assistant-query-selector": "^4.2.0", "js-yaml": "^4.1.0" } } diff --git a/src/custom-sidebar.ts b/src/custom-sidebar.ts index 6a3f29e..e363a7b 100644 --- a/src/custom-sidebar.ts +++ b/src/custom-sidebar.ts @@ -2,7 +2,6 @@ import { HAQuerySelector, HAQuerySelectorEvent, OnListenDetail, - OnPanelLoadDetail, HAElement } from 'home-assistant-query-selector'; import { @@ -39,6 +38,7 @@ class CustomSidebar { (event: CustomEvent) => { this._homeAssistant = event.detail.HOME_ASSISTANT; this._sidebar = event.detail.HA_SIDEBAR; + this._partialPanelResolver = event.detail.PARTIAL_PANEL_RESOLVER; }, { once: true @@ -60,6 +60,7 @@ class CustomSidebar { private _configPromise: Promise; private _homeAssistant: HAElement; + private _partialPanelResolver: HAElement; private _sidebar: HAElement; private _sidebarScroll: number; private _itemTouchedBinded: (event: Event) => Promise; @@ -288,25 +289,25 @@ class CustomSidebar { }); processBottom(); + + this._updateSidebarSelection(); }); } - private async _itemTouched(event: Event): Promise { + private async _itemTouched(): Promise { this._sidebar.selector.$.query(ELEMENT.PAPER_LISTBOX).element .then((paperListBox: PaperListBox): void => { this._sidebarScroll = paperListBox.scrollTop; }); } - private async _updateSidebarSelection(event: CustomEvent): Promise { - - const { HA_SIDEBAR, PARTIAL_PANEL_RESOLVER } = event.detail; + private async _updateSidebarSelection(): Promise { const className = 'iron-selected'; - const panelResolver = await PARTIAL_PANEL_RESOLVER.element as PartialPanelResolver; + const panelResolver = await this._partialPanelResolver.element as PartialPanelResolver; const pathName = panelResolver.__route?.path; - const paperListBox = await HA_SIDEBAR.selector.$.query(ELEMENT.PAPER_LISTBOX).element as PaperListBox; + const paperListBox = await this._sidebar.selector.$.query(ELEMENT.PAPER_LISTBOX).element as PaperListBox; const allLinks = paperListBox.querySelectorAll(`${SELECTOR.SCOPE} > ${SELECTOR.ITEM}`); const activeLink = paperListBox.querySelector( [ diff --git a/yarn.lock b/yarn.lock index 93262b5..0f8bc06 100644 --- a/yarn.lock +++ b/yarn.lock @@ -384,10 +384,10 @@ helpertypes@^0.0.19: resolved "https://registry.yarnpkg.com/helpertypes/-/helpertypes-0.0.19.tgz#6f8cb18e4e1fad73dc103b98e624ac85cb06a720" integrity sha512-J00e55zffgi3yVnUp0UdbMztNkr2PnizEkOe9URNohnrNhW5X0QpegkuLpOmFQInpi93Nb8MCjQRHAiCDF42NQ== -home-assistant-query-selector@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/home-assistant-query-selector/-/home-assistant-query-selector-4.1.0.tgz#d825fd12539001463d21abed41e8251fbb2be8d0" - integrity sha512-8FLanlFOFsg4WcZXwxUy2il2MhY9d3iUzxlaSJwWesHMu/xnnSmCNIqrASf460uEe1YU+WaXNlpZk0DYZg96RA== +home-assistant-query-selector@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/home-assistant-query-selector/-/home-assistant-query-selector-4.2.0.tgz#009ef948f5b9079291a1bc0284c21efa39e82926" + integrity sha512-8VwrqTunsE3sgakCirBdQgrZTvWgT1SIaVthpgVCeaA/8dUK0qQfn3JFUcwaa8xm0NUa8yDgjRkxKe9lGHA65Q== dependencies: shadow-dom-selector "^4.1.2"