Skip to content

Commit

Permalink
Put number selector label above the input (#21835)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Aug 29, 2024
1 parent 362a6f4 commit 18210f3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/components/ha-selector/ha-selector-number.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
import {
css,
CSSResultGroup,
html,
LitElement,
nothing,
PropertyValues,
} from "lit";
import { customElement, property } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { fireEvent } from "../../common/dom/fire_event";
Expand Down Expand Up @@ -60,12 +67,10 @@ export class HaNumberSelector extends LitElement {
}

return html`
${this.label ? html`${this.label}${this.required ? "*" : ""}` : nothing}
<div class="input">
${!isBox
? html`
${this.label
? html`${this.label}${this.required ? "*" : ""}`
: ""}
<ha-slider
labeled
.min=${this.selector.number!.min}
Expand All @@ -75,10 +80,11 @@ export class HaNumberSelector extends LitElement {
.disabled=${this.disabled}
.required=${this.required}
@change=${this._handleSliderChange}
.ticks=${this.selector.number?.slider_ticks}
>
</ha-slider>
`
: ""}
: nothing}
<ha-textfield
.inputMode=${this.selector.number?.step === "any" ||
(this.selector.number?.step ?? 1) % 1 !== 0
Expand All @@ -105,7 +111,7 @@ export class HaNumberSelector extends LitElement {
</div>
${!isBox && this.helper
? html`<ha-input-helper-text>${this.helper}</ha-input-helper-text>`
: ""}
: nothing}
`;
}

Expand Down Expand Up @@ -141,6 +147,9 @@ export class HaNumberSelector extends LitElement {
}
ha-slider {
flex: 1;
margin-right: 16px;
margin-inline-end: 16px;
margin-inline-start: 0;
}
ha-textfield {
--ha-textfield-input-width: 40px;
Expand Down
1 change: 1 addition & 0 deletions src/components/ha-slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class HaSlider extends MdSlider {
--md-sys-color-on-surface: var(--primary-text-color);
--md-slider-handle-width: 14px;
--md-slider-handle-height: 14px;
--md-slider-state-layer-size: 24px;
min-width: 100px;
min-inline-size: 100px;
width: 200px;
Expand Down
1 change: 1 addition & 0 deletions src/data/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export interface NumberSelector {
step?: number | "any";
mode?: "box" | "slider";
unit_of_measurement?: string;
slider_ticks?: boolean;
} | null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class HuiDialogEditSection extends LitElement {
number: {
min: 1,
max: maxColumns,
slider_ticks: true,
},
},
},
Expand Down
1 change: 1 addition & 0 deletions src/panels/lovelace/editor/view-editor/hui-view-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class HuiViewEditor extends LitElement {
min: 1,
max: 10,
mode: "slider",
slider_ticks: true,
},
},
},
Expand Down

0 comments on commit 18210f3

Please sign in to comment.