mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Minor UI bugfixes for selector-datetime and dialog-date-picker (#15759)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
2219c9bbd3
commit
aea668e754
@ -1,5 +1,6 @@
|
|||||||
import "@material/mwc-button/mwc-button";
|
import "@material/mwc-button/mwc-button";
|
||||||
import "app-datepicker";
|
import "app-datepicker";
|
||||||
|
import { format } from "date-fns";
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
@ -66,11 +67,16 @@ export class HaDialogDatePicker extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _setToday() {
|
private _setToday() {
|
||||||
// en-CA locale used for date format YYYY-MM-DD
|
const today = new Date();
|
||||||
this._value = new Date().toLocaleDateString("en-CA");
|
this._value = format(today, "yyyy-MM-dd");
|
||||||
}
|
}
|
||||||
|
|
||||||
private _setValue() {
|
private _setValue() {
|
||||||
|
if (!this._value) {
|
||||||
|
// Date picker opens to today if value is undefined. If user click OK
|
||||||
|
// without changing the date, should return todays date, not undefined.
|
||||||
|
this._setToday();
|
||||||
|
}
|
||||||
this._params?.onChange(this._value!);
|
this._params?.onChange(this._value!);
|
||||||
this.closeDialog();
|
this.closeDialog();
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ export class HaDateTimeSelector extends LitElement {
|
|||||||
</ha-date-input>
|
</ha-date-input>
|
||||||
<ha-time-input
|
<ha-time-input
|
||||||
enable-second
|
enable-second
|
||||||
.value=${values?.[1] || "0:00:00"}
|
.value=${values?.[1] || "00:00:00"}
|
||||||
.locale=${this.hass.locale}
|
.locale=${this.hass.locale}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
@ -60,9 +60,11 @@ export class HaDateTimeSelector extends LitElement {
|
|||||||
|
|
||||||
private _valueChanged(ev: CustomEvent): void {
|
private _valueChanged(ev: CustomEvent): void {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
fireEvent(this, "value-changed", {
|
if (this._dateInput.value && this._timeInput.value) {
|
||||||
value: `${this._dateInput.value} ${this._timeInput.value}`,
|
fireEvent(this, "value-changed", {
|
||||||
});
|
value: `${this._dateInput.value} ${this._timeInput.value}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static styles = css`
|
static styles = css`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user