import "@material/mwc-menu"; import type { Corner, Menu, MenuCorner } from "@material/mwc-menu"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { customElement, property, query } from "lit/decorators"; @customElement("ha-button-menu") export class HaButtonMenu extends LitElement { @property() public corner: Corner = "TOP_START"; @property() public menuCorner: MenuCorner = "START"; @property({ type: Number }) public x?: number; @property({ type: Number }) public y?: number; @property({ type: Boolean }) public multi = false; @property({ type: Boolean }) public activatable = false; @property({ type: Boolean }) public disabled = false; @property({ type: Boolean }) public fixed = false; @query("mwc-menu", true) private _menu?: Menu; public get items() { return this._menu?.items; } public get selected() { return this._menu?.selected; } protected render(): TemplateResult { return html`
`; } protected firstUpdated(changedProps): void { super.firstUpdated(changedProps); if (document.dir === "rtl") { this.updateComplete.then(() => { this.querySelectorAll("mwc-list-item").forEach((item) => { const style = document.createElement("style"); style.innerHTML = "span.material-icons:first-of-type { margin-left: var(--mdc-list-item-graphic-margin, 32px) !important; margin-right: 0px !important;}"; item!.shadowRoot!.appendChild(style); }); }); } } private _handleClick(): void { if (this.disabled) { return; } this._menu!.anchor = this; this._menu!.show(); } static get styles(): CSSResultGroup { return css` :host { display: inline-block; position: relative; } ::slotted([disabled]) { color: var(--disabled-text-color); } `; } } declare global { interface HTMLElementTagNameMap { "ha-button-menu": HaButtonMenu; } }