Skip to content

Commit

Permalink
Range: adhere to decimal points from number or string (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevireilly authored Mar 19, 2024
1 parent 38789e6 commit bb13682
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/v3/src/esp-entity-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,21 +313,27 @@ class ActionRenderer {
entity: entityConfig,
action: string,
opt: string,
value: string | number,
min: number | undefined,
max: number | undefined,
step: number | undefined
value: number | string,
min?: number,
max?: number,
step = 1
) {
const val = Number(value);
let stepString = step.toString();
let numDecimalPlaces = 0
if (stepString.indexOf('.') !== -1) {
numDecimalPlaces = stepString.split('.')[1].length;
}
return html`<div class="range">
<label>${min || 0}</label>
<input
type="${entity.mode == 1 ? "number" : "range"}"
name="${entity.unique_id}"
id="${entity.unique_id}"
step="${step || 1}"
min="${min || Math.min(0, value as number)}"
max="${max || Math.max(10, value as number)}"
.value="${value!}"
step="${step}"
min="${min || Math.min(0, val)}"
max="${max || Math.max(10, val)}"
.value="${(val.toFixed(numDecimalPlaces))}"
@change="${(e: Event) => {
const val = (<HTMLTextAreaElement>e.target)?.value;
this.actioner?.restAction(entity, `${action}?${opt}=${val}`);
Expand Down

0 comments on commit bb13682

Please sign in to comment.