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
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();
}