Minor UI bugfixes for selector-datetime and dialog-date-picker (#15759)

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
karwosts 2023-05-31 05:26:01 -07:00 committed by GitHub
parent 2219c9bbd3
commit aea668e754
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -1,5 +1,6 @@
import "@material/mwc-button/mwc-button";
import "app-datepicker";
import { format } from "date-fns";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../common/dom/fire_event";
@ -66,11 +67,16 @@ export class HaDialogDatePicker extends LitElement {
}
private _setToday() {
// en-CA locale used for date format YYYY-MM-DD
this._value = new Date().toLocaleDateString("en-CA");
const today = new Date();
this._value = format(today, "yyyy-MM-dd");
}
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.closeDialog();
}

View File

@ -45,7 +45,7 @@ export class HaDateTimeSelector extends LitElement {
</ha-date-input>
<ha-time-input
enable-second
.value=${values?.[1] || "0:00:00"}
.value=${values?.[1] || "00:00:00"}
.locale=${this.hass.locale}
.disabled=${this.disabled}
.required=${this.required}
@ -60,9 +60,11 @@ export class HaDateTimeSelector extends LitElement {
private _valueChanged(ev: CustomEvent): void {
ev.stopPropagation();
fireEvent(this, "value-changed", {
value: `${this._dateInput.value} ${this._timeInput.value}`,
});
if (this._dateInput.value && this._timeInput.value) {
fireEvent(this, "value-changed", {
value: `${this._dateInput.value} ${this._timeInput.value}`,
});
}
}
static styles = css`