From 380509cf57228ebd2cf2b6f13b442b972adf44bb Mon Sep 17 00:00:00 2001 From: Ludeeus Date: Tue, 26 Oct 2021 15:17:39 +0000 Subject: [PATCH] Fix clickhandlers --- gallery/src/ha-gallery.js | 12 ++++++++++++ src/components/ha-chip-set.ts | 15 --------------- src/components/ha-chip.ts | 26 ++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/gallery/src/ha-gallery.js b/gallery/src/ha-gallery.js index fc1a03df24..dce8272b50 100644 --- a/gallery/src/ha-gallery.js +++ b/gallery/src/ha-gallery.js @@ -187,6 +187,18 @@ class HaGallery extends PolymerElement { }) ); + this.addEventListener("chip-clicked", () => + this.$.notifications.showDialog({ + message: "Chip clicked", + }) + ); + + this.addEventListener("chip-clicked-trailing", () => + this.$.notifications.showDialog({ + message: "Chip trailing icon clicked", + }) + ); + this.addEventListener("hass-more-info", (ev) => { if (ev.detail.entityId) { this.$.notifications.showDialog({ diff --git a/src/components/ha-chip-set.ts b/src/components/ha-chip-set.ts index b74609fd55..28743baf1a 100644 --- a/src/components/ha-chip-set.ts +++ b/src/components/ha-chip-set.ts @@ -9,16 +9,8 @@ import { unsafeCSS, } from "lit"; import { customElement, property } from "lit/decorators"; -import { fireEvent } from "../common/dom/fire_event"; import "./ha-chip"; -declare global { - // for fire event - interface HASSDomEvents { - "chip-clicked": { index: string }; - } -} - export interface HaChipSetItem { label?: string; leadingIcon?: string; @@ -38,7 +30,6 @@ export class HaChipSet extends LitElement { (item, idx) => html` +
${this.leadingIcon ? html`
- + ${this.label || html``} @@ -45,6 +57,7 @@ export class HaChip extends LitElement { ${this.trailingIcon ? html` @@ -56,6 +69,15 @@ export class HaChip extends LitElement { `; } + private _handleClick(): void { + fireEvent(this, "chip-clicked"); + } + + private _handleTrailingClick(ev: Event): void { + ev.stopPropagation(); + fireEvent(this, "chip-clicked-trailing"); + } + static get styles(): CSSResultGroup { return css` ${unsafeCSS(chipStyles)}