mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-07 16:37:48 +00:00
Fix clickhandlers
This commit is contained in:
parent
88139f64ab
commit
380509cf57
@ -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) => {
|
this.addEventListener("hass-more-info", (ev) => {
|
||||||
if (ev.detail.entityId) {
|
if (ev.detail.entityId) {
|
||||||
this.$.notifications.showDialog({
|
this.$.notifications.showDialog({
|
||||||
|
@ -9,16 +9,8 @@ import {
|
|||||||
unsafeCSS,
|
unsafeCSS,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
|
||||||
import "./ha-chip";
|
import "./ha-chip";
|
||||||
|
|
||||||
declare global {
|
|
||||||
// for fire event
|
|
||||||
interface HASSDomEvents {
|
|
||||||
"chip-clicked": { index: string };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface HaChipSetItem {
|
export interface HaChipSetItem {
|
||||||
label?: string;
|
label?: string;
|
||||||
leadingIcon?: string;
|
leadingIcon?: string;
|
||||||
@ -38,7 +30,6 @@ export class HaChipSet extends LitElement {
|
|||||||
(item, idx) =>
|
(item, idx) =>
|
||||||
html`
|
html`
|
||||||
<ha-chip
|
<ha-chip
|
||||||
@click=${this._handleClick}
|
|
||||||
.index=${idx}
|
.index=${idx}
|
||||||
.label=${item.label}
|
.label=${item.label}
|
||||||
.leadingIcon=${item.leadingIcon}
|
.leadingIcon=${item.leadingIcon}
|
||||||
@ -53,12 +44,6 @@ export class HaChipSet extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleClick(ev): void {
|
|
||||||
fireEvent(this, "chip-clicked", {
|
|
||||||
index: ev.currentTarget.index,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return css`
|
||||||
${unsafeCSS(chipStyles)}
|
${unsafeCSS(chipStyles)}
|
||||||
|
@ -9,6 +9,15 @@ import {
|
|||||||
unsafeCSS,
|
unsafeCSS,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
// for fire event
|
||||||
|
interface HASSDomEvents {
|
||||||
|
"chip-clicked": undefined;
|
||||||
|
"chip-clicked-trailing": undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@customElement("ha-chip")
|
@customElement("ha-chip")
|
||||||
export class HaChip extends LitElement {
|
export class HaChip extends LitElement {
|
||||||
@ -22,7 +31,10 @@ export class HaChip extends LitElement {
|
|||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<div class="mdc-chip ${this.outlined ? "outlined" : ""}">
|
<div
|
||||||
|
class="mdc-chip ${this.outlined ? "outlined" : ""}"
|
||||||
|
@click=${this._handleClick}
|
||||||
|
>
|
||||||
${this.leadingIcon
|
${this.leadingIcon
|
||||||
? html`<span role="gridcell">
|
? html`<span role="gridcell">
|
||||||
<span role="button" tabindex="0" class="mdc-chip__primary-action"
|
<span role="button" tabindex="0" class="mdc-chip__primary-action"
|
||||||
@ -35,7 +47,7 @@ export class HaChip extends LitElement {
|
|||||||
: ""}
|
: ""}
|
||||||
<div class="mdc-chip__ripple"></div>
|
<div class="mdc-chip__ripple"></div>
|
||||||
<span role="gridcell">
|
<span role="gridcell">
|
||||||
<span role="button" tabindex="0" class="mdc-chip__primary-action">
|
<span role="row" tabindex="0" class="mdc-chip__primary-action">
|
||||||
<span class="mdc-chip__text">
|
<span class="mdc-chip__text">
|
||||||
${this.label || html`<slot></slot>`}
|
${this.label || html`<slot></slot>`}
|
||||||
</span>
|
</span>
|
||||||
@ -45,6 +57,7 @@ export class HaChip extends LitElement {
|
|||||||
<span role="button" tabindex="-1" class="mdc-chip__primary-action">
|
<span role="button" tabindex="-1" class="mdc-chip__primary-action">
|
||||||
${this.trailingIcon
|
${this.trailingIcon
|
||||||
? html`<ha-svg-icon
|
? html`<ha-svg-icon
|
||||||
|
@click=${this._handleTrailingClick}
|
||||||
class="mdc-chip__icon mdc-chip__icon--trailing"
|
class="mdc-chip__icon mdc-chip__icon--trailing"
|
||||||
.path=${this.trailingIcon}
|
.path=${this.trailingIcon}
|
||||||
>
|
>
|
||||||
@ -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 {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return css`
|
||||||
${unsafeCSS(chipStyles)}
|
${unsafeCSS(chipStyles)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user