From 9bef5c2af99ed4951980089eb2d86edd4821e3fc Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Tue, 2 Apr 2024 19:42:54 +0200 Subject: [PATCH] Add clear button to search field (#20332) --- src/components/search-input-outlined.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/components/search-input-outlined.ts b/src/components/search-input-outlined.ts index f949323cacc4..5e40df35c923 100644 --- a/src/components/search-input-outlined.ts +++ b/src/components/search-input-outlined.ts @@ -1,5 +1,12 @@ -import { mdiMagnify } from "@mdi/js"; -import { CSSResultGroup, LitElement, TemplateResult, css, html } from "lit"; +import { mdiClose, mdiMagnify } from "@mdi/js"; +import { + CSSResultGroup, + LitElement, + TemplateResult, + css, + html, + nothing, +} from "lit"; import { customElement, property, query } from "lit/decorators"; import { fireEvent } from "../common/dom/fire_event"; import { HomeAssistant } from "../types"; @@ -54,6 +61,15 @@ class SearchInputOutlined extends LitElement { .path=${mdiMagnify} > + ${this.filter + ? html` + ` + : nothing} `; } @@ -66,12 +82,17 @@ class SearchInputOutlined extends LitElement { this._filterChanged(e.target.value); } + private async _clearSearch() { + this._filterChanged(""); + } + static get styles(): CSSResultGroup { return css` :host { display: inline-flex; /* For iOS */ z-index: 0; + --mdc-icon-button-size: 24px; } ha-outlined-text-field { display: block;