Skip to content

Commit

Permalink
Don't override ranges provided by parent (#18444)
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten authored Oct 27, 2023
1 parent 4f09485 commit 54758b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/components/ha-date-range-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export class HaDateRangePicker extends LitElement {

@property() public ranges?: DateRangePickerRanges | false;

@state() private _ranges?: DateRangePickerRanges;

@property() public autoApply = false;

@property() public timePicker = true;
Expand Down Expand Up @@ -93,7 +95,7 @@ export class HaDateRangePicker extends LitElement {
}
);

this.ranges = {
this._ranges = {
[this.hass.localize("ui.components.date-range-picker.ranges.today")]: [
calcDate(today, startOfDay, this.hass.locale, this.hass.config, {
weekStartsOn,
Expand Down Expand Up @@ -206,15 +208,15 @@ export class HaDateRangePicker extends LitElement {
.path=${mdiCalendar}
></ha-icon-button>`}
</div>
${this.ranges
${this.ranges !== false && (this.ranges || this._ranges)
? html`<div
slot="ranges"
class="date-range-ranges"
.dir=${this._rtlDirection}
>
<mwc-list @action=${this._setDateRange} activatable>
${Object.keys(this.ranges).map(
(name) => html`<mwc-list-item> ${name} </mwc-list-item>`
${Object.keys(this.ranges || this._ranges!).map(
(name) => html`<mwc-list-item>${name}</mwc-list-item>`
)}
</mwc-list>
</div>`
Expand All @@ -234,7 +236,9 @@ export class HaDateRangePicker extends LitElement {
}

private _setDateRange(ev: CustomEvent<ActionDetail>) {
const dateRange = Object.values(this.ranges!)[ev.detail.index];
const dateRange = Object.values(this.ranges || this._ranges!)[
ev.detail.index
];
const dateRangePicker = this._dateRangePicker;
dateRangePicker.clickRange(dateRange);
dateRangePicker.clickedApply();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class HuiEnergyPeriodSelector extends SubscribeMixin(LitElement) {

@state() _endDate?: Date;

@state() private _ranges?: DateRangePickerRanges;
@state() private _ranges: DateRangePickerRanges = {};

@state() private _compare = false;

Expand Down

0 comments on commit 54758b5

Please sign in to comment.