Skip to content

Commit

Permalink
Multi textfield helper (#23649)
Browse files Browse the repository at this point in the history
Co-authored-by: Bram Kragten <[email protected]>
  • Loading branch information
karwosts and bramkragten authored Jan 20, 2025
1 parent fc29002 commit 3feedb7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/components/ha-multi-textfield.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { mdiDeleteOutline, mdiPlus } from "@mdi/js";
import type { CSSResultGroup } from "lit";
import { LitElement, css, html } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { fireEvent } from "../common/dom/fire_event";
import { haStyle } from "../resources/styles";
import type { HomeAssistant } from "../types";
import "./ha-button";
import "./ha-icon-button";
import "./ha-textfield";
import "./ha-input-helper-text";
import type { HaTextField } from "./ha-textfield";

@customElement("ha-multi-textfield")
Expand All @@ -20,6 +21,8 @@ class HaMultiTextField extends LitElement {

@property() public label?: string;

@property({ attribute: false }) public helper?: string;

@property({ attribute: false }) public inputType?: string;

@property({ attribute: false }) public inputSuffix?: string;
Expand Down Expand Up @@ -69,12 +72,21 @@ class HaMultiTextField extends LitElement {
</div>
`;
})}
<div class="layout horizontal center-center">
<div class="layout horizontal">
<ha-button @click=${this._addItem} .disabled=${this.disabled}>
${this.addLabel ?? this.hass?.localize("ui.common.add") ?? "Add"}
${this.addLabel ??
(this.label
? this.hass?.localize("ui.components.multi-textfield.add_item", {
item: this.label,
})
: this.hass?.localize("ui.common.add")) ??
"Add"}
<ha-svg-icon slot="icon" .path=${mdiPlus}></ha-svg-icon>
</ha-button>
</div>
${this.helper
? html`<ha-input-helper-text>${this.helper}</ha-input-helper-text>`
: nothing}
`;
}

Expand Down
1 change: 1 addition & 0 deletions src/components/ha-selector/ha-selector-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class HaTextSelector extends LitElement {
.inputType=${this.selector.text?.type}
.inputSuffix=${this.selector.text?.suffix}
.inputPrefix=${this.selector.text?.prefix}
.helper=${this.helper}
.autocomplete=${this.selector.text?.autocomplete}
@value-changed=${this._handleChange}
>
Expand Down
3 changes: 3 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,9 @@
"last_updated": "Last updated",
"remaining_time": "Remaining time",
"install_status": "Install status"
},
"multi-textfield": {
"add_item": "Add {item}"
}
},
"dialogs": {
Expand Down

0 comments on commit 3feedb7

Please sign in to comment.