Support typing negative values for ha-form-float (#13940)

This commit is contained in:
Kyle Niewiada 2022-10-03 05:02:00 -04:00 committed by GitHub
parent 200fff506c
commit 952b433b2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,6 +26,7 @@ export class HaFormFloat extends LitElement implements HaFormElement {
protected render(): TemplateResult {
return html`
<ha-textfield
type="numeric"
inputMode="decimal"
.label=${this.label}
.value=${this.data !== undefined ? this.data : ""}
@ -55,6 +56,11 @@ export class HaFormFloat extends LitElement implements HaFormElement {
return;
}
// Allow user to start typing a negative value
if (rawValue === "-") {
return;
}
if (rawValue !== "") {
value = parseFloat(rawValue);
if (isNaN(value)) {