Skip to content

Commit

Permalink
use null instead of undefined.
Browse files Browse the repository at this point in the history
  • Loading branch information
schelv committed Dec 2, 2023
1 parent 3c22b0f commit a893222
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/components/ha-base-time-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,8 @@ export class HaBaseTimeInput extends LitElement {
}

private _clearValue(): void {
const value = undefined;

fireEvent(this, "value-changed", {
value,
value: null,
});
}

Expand Down
15 changes: 8 additions & 7 deletions src/components/ha-time-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,20 @@ export class HaTimeInput extends LitElement {
`;
}

private _timeChanged(ev: CustomEvent<{ value: TimeChangedEvent }>) {
private _timeChanged(ev: CustomEvent<{ value: TimeChangedEvent | null }>) {
ev.stopPropagation();
const eventValue = ev.detail.value;

const useAMPM = useAmPm(this.locale);
let value;

if (typeof eventValue === "undefined") {
value = undefined;
} else if (
!isNaN(eventValue.hours) ||
!isNaN(eventValue.minutes) ||
!isNaN(eventValue.seconds)
// An eventValue of null means the value is being cleared,
// and value will (intentionally) be left undefined.
if (
eventValue !== null &&
(!isNaN(eventValue.hours) ||
!isNaN(eventValue.minutes) ||
!isNaN(eventValue.seconds))
) {
let hours = eventValue.hours || 0;
if (eventValue && useAMPM) {
Expand Down

0 comments on commit a893222

Please sign in to comment.