Skip to content

Commit

Permalink
Fix sidebar selection
Browse files Browse the repository at this point in the history
  • Loading branch information
elchininet committed Jan 13, 2024
1 parent bb11218 commit 3fb2d24
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
15 changes: 8 additions & 7 deletions src/custom-sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
HAQuerySelector,
HAQuerySelectorEvent,
OnListenDetail,
OnPanelLoadDetail,
HAElement
} from 'home-assistant-query-selector';
import {
Expand Down Expand Up @@ -39,6 +38,7 @@ class CustomSidebar {
(event: CustomEvent<OnListenDetail>) => {
this._homeAssistant = event.detail.HOME_ASSISTANT;
this._sidebar = event.detail.HA_SIDEBAR;
this._partialPanelResolver = event.detail.PARTIAL_PANEL_RESOLVER;
},
{
once: true
Expand All @@ -60,6 +60,7 @@ class CustomSidebar {

private _configPromise: Promise<Config>;
private _homeAssistant: HAElement;
private _partialPanelResolver: HAElement;
private _sidebar: HAElement;
private _sidebarScroll: number;
private _itemTouchedBinded: (event: Event) => Promise<void>;
Expand Down Expand Up @@ -288,25 +289,25 @@ class CustomSidebar {
});

processBottom();

this._updateSidebarSelection();

});
}

private async _itemTouched(event: Event): Promise<void> {
private async _itemTouched(): Promise<void> {
this._sidebar.selector.$.query(ELEMENT.PAPER_LISTBOX).element
.then((paperListBox: PaperListBox): void => {
this._sidebarScroll = paperListBox.scrollTop;
});
}

private async _updateSidebarSelection(event: CustomEvent<OnPanelLoadDetail>): Promise<void> {

const { HA_SIDEBAR, PARTIAL_PANEL_RESOLVER } = event.detail;
private async _updateSidebarSelection(): Promise<void> {

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<HTMLAnchorElement>(`${SELECTOR.SCOPE} > ${SELECTOR.ITEM}`);
const activeLink = paperListBox.querySelector<HTMLAnchorElement>(
[
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 3fb2d24

Please sign in to comment.