mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 10:16:46 +00:00
Fix sidebar keyboard navigation in edit mode (#25376)
This commit is contained in:
parent
1508c7c905
commit
7919028780
@ -24,9 +24,10 @@ import {
|
|||||||
customElement,
|
customElement,
|
||||||
eventOptions,
|
eventOptions,
|
||||||
property,
|
property,
|
||||||
state,
|
|
||||||
query,
|
query,
|
||||||
|
state,
|
||||||
} from "lit/decorators";
|
} from "lit/decorators";
|
||||||
|
import { classMap } from "lit/directives/class-map";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { storage } from "../common/decorators/storage";
|
import { storage } from "../common/decorators/storage";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
@ -45,13 +46,13 @@ import { haStyleScrollbar } from "../resources/styles";
|
|||||||
import type { HomeAssistant, PanelInfo, Route } from "../types";
|
import type { HomeAssistant, PanelInfo, Route } from "../types";
|
||||||
import "./ha-icon";
|
import "./ha-icon";
|
||||||
import "./ha-icon-button";
|
import "./ha-icon-button";
|
||||||
|
import "./ha-md-list";
|
||||||
|
import "./ha-md-list-item";
|
||||||
|
import type { HaMdListItem } from "./ha-md-list-item";
|
||||||
import "./ha-menu-button";
|
import "./ha-menu-button";
|
||||||
import "./ha-sortable";
|
import "./ha-sortable";
|
||||||
import "./ha-svg-icon";
|
import "./ha-svg-icon";
|
||||||
import "./user/ha-user-badge";
|
import "./user/ha-user-badge";
|
||||||
import "./ha-md-list";
|
|
||||||
import "./ha-md-list-item";
|
|
||||||
import type { HaMdListItem } from "./ha-md-list-item";
|
|
||||||
|
|
||||||
const SHOW_AFTER_SPACER = ["config", "developer-tools"];
|
const SHOW_AFTER_SPACER = ["config", "developer-tools"];
|
||||||
|
|
||||||
@ -407,6 +408,7 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
return html`
|
return html`
|
||||||
|
<ha-sortable .disabled=${!this.editMode} draggable-selector=".draggable" @item-moved=${this._panelMoved}>
|
||||||
<ha-md-list
|
<ha-md-list
|
||||||
class="ha-scrollbar"
|
class="ha-scrollbar"
|
||||||
@focusin=${this._listboxFocusIn}
|
@focusin=${this._listboxFocusIn}
|
||||||
@ -420,11 +422,16 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
${this._renderSpacer()}
|
${this._renderSpacer()}
|
||||||
${this._renderPanels(afterSpacer, selectedPanel)}
|
${this._renderPanels(afterSpacer, selectedPanel)}
|
||||||
${this._renderExternalConfiguration()}
|
${this._renderExternalConfiguration()}
|
||||||
</ha-md-list>
|
</ha-md-list>
|
||||||
|
</ha-sortable>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _renderPanels(panels: PanelInfo[], selectedPanel: string) {
|
private _renderPanels(
|
||||||
|
panels: PanelInfo[],
|
||||||
|
selectedPanel: string,
|
||||||
|
sortable = false
|
||||||
|
) {
|
||||||
return panels.map((panel) =>
|
return panels.map((panel) =>
|
||||||
this._renderPanel(
|
this._renderPanel(
|
||||||
panel.url_path,
|
panel.url_path,
|
||||||
@ -437,17 +444,26 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
: panel.url_path in PANEL_ICONS
|
: panel.url_path in PANEL_ICONS
|
||||||
? PANEL_ICONS[panel.url_path]
|
? PANEL_ICONS[panel.url_path]
|
||||||
: undefined,
|
: undefined,
|
||||||
selectedPanel
|
selectedPanel,
|
||||||
|
sortable
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _renderPanelsEdit(beforeSpacer: PanelInfo[], selectedPanel: string) {
|
||||||
|
return html`
|
||||||
|
${this._renderPanels(beforeSpacer, selectedPanel, true)}
|
||||||
|
${this._renderSpacer()}${this._renderHiddenPanels()}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
private _renderPanel(
|
private _renderPanel(
|
||||||
urlPath: string,
|
urlPath: string,
|
||||||
title: string | null,
|
title: string | null,
|
||||||
icon: string | null | undefined,
|
icon: string | null | undefined,
|
||||||
iconPath: string | null | undefined,
|
iconPath: string | null | undefined,
|
||||||
selectedPanel: string
|
selectedPanel: string,
|
||||||
|
sortable = false
|
||||||
) {
|
) {
|
||||||
return urlPath === "config"
|
return urlPath === "config"
|
||||||
? this._renderConfiguration(title, selectedPanel)
|
? this._renderConfiguration(title, selectedPanel)
|
||||||
@ -455,7 +471,10 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
<ha-md-list-item
|
<ha-md-list-item
|
||||||
.href=${this.editMode ? undefined : `/${urlPath}`}
|
.href=${this.editMode ? undefined : `/${urlPath}`}
|
||||||
type="link"
|
type="link"
|
||||||
class=${selectedPanel === urlPath ? "selected" : ""}
|
class=${classMap({
|
||||||
|
selected: selectedPanel === urlPath,
|
||||||
|
draggable: this.editMode && sortable,
|
||||||
|
})}
|
||||||
@mouseenter=${this._itemMouseEnter}
|
@mouseenter=${this._itemMouseEnter}
|
||||||
@mouseleave=${this._itemMouseLeave}
|
@mouseleave=${this._itemMouseLeave}
|
||||||
>
|
>
|
||||||
@ -496,15 +515,6 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
this._panelOrder = panelOrder;
|
this._panelOrder = panelOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _renderPanelsEdit(beforeSpacer: PanelInfo[], selectedPanel: string) {
|
|
||||||
return html`
|
|
||||||
<ha-sortable .disabled=${!this.editMode} @item-moved=${this._panelMoved}
|
|
||||||
><div>${this._renderPanels(beforeSpacer, selectedPanel)}</div>
|
|
||||||
</ha-sortable>
|
|
||||||
${this._renderSpacer()}${this._renderHiddenPanels()}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _renderHiddenPanels() {
|
private _renderHiddenPanels() {
|
||||||
return html`${this._hiddenPanels.length
|
return html`${this._hiddenPanels.length
|
||||||
? html`${this._hiddenPanels.map((url) => {
|
? html`${this._hiddenPanels.map((url) => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { css } from "lit";
|
import { css } from "lit";
|
||||||
|
|
||||||
export const sidebarEditStyle = css`
|
export const sidebarEditStyle = css`
|
||||||
ha-sortable ha-md-list-item:nth-child(2n) {
|
ha-sortable ha-md-list-item.draggable:nth-child(2n) {
|
||||||
animation-name: keyframes1;
|
animation-name: keyframes1;
|
||||||
animation-iteration-count: infinite;
|
animation-iteration-count: infinite;
|
||||||
transform-origin: 50% 10%;
|
transform-origin: 50% 10%;
|
||||||
@ -9,7 +9,7 @@ export const sidebarEditStyle = css`
|
|||||||
animation-duration: 0.25s;
|
animation-duration: 0.25s;
|
||||||
}
|
}
|
||||||
|
|
||||||
ha-sortable ha-md-list-item:nth-child(2n-1) {
|
ha-sortable ha-md-list-item.draggable:nth-child(2n-1) {
|
||||||
animation-name: keyframes2;
|
animation-name: keyframes2;
|
||||||
animation-iteration-count: infinite;
|
animation-iteration-count: infinite;
|
||||||
animation-direction: alternate;
|
animation-direction: alternate;
|
||||||
@ -18,8 +18,7 @@ export const sidebarEditStyle = css`
|
|||||||
animation-duration: 0.33s;
|
animation-duration: 0.33s;
|
||||||
}
|
}
|
||||||
|
|
||||||
ha-sortable ha-md-list-item {
|
ha-sortable ha-md-list-item.draggable {
|
||||||
height: 48px;
|
|
||||||
cursor: grab;
|
cursor: grab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user