diff --git a/src/panels/lovelace/views/hui-sections-view.ts b/src/panels/lovelace/views/hui-sections-view.ts index 2e2320fa54..a5549f4ab9 100644 --- a/src/panels/lovelace/views/hui-sections-view.ts +++ b/src/panels/lovelace/views/hui-sections-view.ts @@ -1,4 +1,11 @@ -import { mdiArrowAll, mdiDelete, mdiPencil, mdiViewGridPlus } from "@mdi/js"; +import { + mdiArrowAll, + mdiArrowDown, + mdiArrowUp, + mdiDelete, + mdiPencil, + mdiViewGridPlus, +} from "@mdi/js"; import { CSSResultGroup, LitElement, css, html, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; import { repeat } from "lit/directives/repeat"; @@ -21,6 +28,8 @@ import { } from "../editor/lovelace-path"; import { HuiSection } from "../sections/hui-section"; import type { Lovelace, LovelaceBadge } from "../types"; +import { isTouch } from "../../../util/is_touch"; +import { listenMediaQuery } from "../../../common/dom/media_query"; @customElement("hui-sections-view") export class SectionsView extends LitElement implements LovelaceViewElement { @@ -38,6 +47,23 @@ export class SectionsView extends LitElement implements LovelaceViewElement { @state() private _config?: LovelaceViewConfig; + @state() private _narrow = false; + + private _unsubMql?: () => void; + + public connectedCallback() { + super.connectedCallback(); + this._unsubMql = listenMediaQuery("(max-width: 600px)", (matches) => { + this._narrow = matches; + }); + } + + public disconnectedCallback() { + super.disconnectedCallback(); + this._unsubMql?.(); + this._unsubMql = undefined; + } + public setConfig(config: LovelaceViewConfig): void { this._config = config; } @@ -58,12 +84,14 @@ export class SectionsView extends LitElement implements LovelaceViewElement { const editMode = this.lovelace.editMode; + const supportDnD = !(isTouch && this._narrow); + return html` ${this.badges.length > 0 ? html`
${this.badges}
` : ""}
- + ${supportDnD + ? html` + + ` + : html` + + + `}