mirror of
https://github.com/home-assistant/frontend.git
synced 2026-02-04 01:10:33 -06:00
Update ha-base-time-input to accept decimal input for seconds (#29058)
* Update ha-base-time-input to accept decimal input for seconds * Add support for decimal values in time formatting ha-base-time-input
This commit is contained in:
parent
081b0a0222
commit
35c668744a
@ -208,7 +208,8 @@ export class HaBaseTimeInput extends LitElement {
|
||||
? html`<ha-textfield
|
||||
id="sec"
|
||||
type="number"
|
||||
inputmode="numeric"
|
||||
inputmode="decimal"
|
||||
step="any"
|
||||
.value=${this._formatValue(this.seconds)}
|
||||
.label=${this.secLabel}
|
||||
@change=${this._valueChanged}
|
||||
@ -217,7 +218,6 @@ export class HaBaseTimeInput extends LitElement {
|
||||
no-spinner
|
||||
.required=${this.required}
|
||||
.autoValidate=${this.autoValidate}
|
||||
maxlength="2"
|
||||
max="59"
|
||||
min="0"
|
||||
.disabled=${this.disabled}
|
||||
@ -311,7 +311,8 @@ export class HaBaseTimeInput extends LitElement {
|
||||
* Format time fragments
|
||||
*/
|
||||
private _formatValue(value: number, padding = 2) {
|
||||
return value.toString().padStart(padding, "0");
|
||||
const str = value.toString();
|
||||
return str.includes(".") ? str : str.padStart(padding, "0");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -27,6 +27,12 @@ describe("createDurationData", () => {
|
||||
expect(createDurationData(3600)).toEqual({ seconds: 3600 });
|
||||
});
|
||||
|
||||
it("should parse decimal seconds correctly", () => {
|
||||
expect(createDurationData(0.5)).toEqual({ seconds: 0.5 });
|
||||
expect(createDurationData(0.2)).toEqual({ seconds: 0.2 });
|
||||
expect(createDurationData(1.25)).toEqual({ seconds: 1.25 });
|
||||
});
|
||||
|
||||
it("should parse object duration without days correctly", () => {
|
||||
expect(createDurationData({ hours: 1, minutes: 30 })).toEqual({
|
||||
hours: 1,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user