Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert paper-input to ha-textfield #45

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 33 additions & 16 deletions search-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,26 @@ class SearchCard extends ct.LitElement {
return ct.LitHtml `
<ha-card>
<div id="searchContainer">
<paper-input id="searchText"
@value-changed="${this._valueChanged}"
no-label-float type="text" autocomplete="off"
label="${this.search_text}">
<ha-icon icon="mdi:magnify" id="searchIcon"
slot="prefix"></ha-icon>
<ha-icon-button slot="suffix"
@click="${this._clearInput}"
alt="Clear"
title="Clear"><ha-icon icon="mdi:close"></ha-icon></ha-icon-button>
</paper-input>
<div id="searchTextFieldContainer">
<ha-textfield
id="searchText"
@input="${this._valueChanged}"
no-label-float type="text" autocomplete="off"
icon iconTrailing
label="${this.search_text}"
>
<ha-icon icon="mdi:magnify" id="searchIcon" slot="leadingIcon"></ha-icon>
<ha-icon-button
slot="trailingIcon"
@click="${this._clearInput}"
alt="Clear"
title="Clear"
>
<ha-icon icon="mdi:close"></ha-icon>
</ha-icon-button>
</ha-textfield>
</div>

${results.length > 0 ?
ct.LitHtml `<div id="count">Showing ${results.length} of ${this.results.length} results</div>`
: ''}
Expand Down Expand Up @@ -106,12 +115,15 @@ class SearchCard extends ct.LitElement {
_clearInput()
{
this.shadowRoot.getElementById('searchText').value = '';
super.update()
this._updateSearchResults('');
}

_valueChanged(ev) {
var searchText = ev.target.value;
this._updateSearchResults(searchText);
}

_updateSearchResults(searchText) {
this.results = [];
this.active_actions = [];

Expand Down Expand Up @@ -175,6 +187,14 @@ class SearchCard extends ct.LitElement {
margin-left: auto;
margin-right: auto;
}
#searchTextFieldContainer {
display: flex;
padding-top: 5px;
padding-bottom: 5px;
}
#searchText {
flex-grow: 1;
}
#count {
text-align: right;
font-style: italic;
Expand All @@ -187,9 +207,6 @@ class SearchCard extends ct.LitElement {
margin-left: auto;
margin-right: auto;
}
#searchIcon {
padding: 10px;
}
`;
}
}
Expand All @@ -211,4 +228,4 @@ window.customCards.push({
name: "Search Card",
preview: true,
description: "Card to search entities"
});
});