mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +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 "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();
|
||||
}
|
||||
|
@ -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`
|
||||
|
Loading…
x
Reference in New Issue
Block a user