Skip to content

Commit 33dd9a4

Browse files
authored
feat(datepicker): when datepicker value updated datepicker input valu… (#983)
…e should also updated
1 parent 004e769 commit 33dd9a4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/components/datepicker/bl-datepicker.test.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { aTimeout, expect, fixture, html } from "@open-wc/testing";
1+
import { aTimeout, elementUpdated, expect, fixture, html } from "@open-wc/testing";
22
import { BlButton, BlDatePicker } from "../../baklava";
33
import { CALENDAR_TYPES } from "../calendar/bl-calendar.constant";
44
import sinon from "sinon";
@@ -385,4 +385,13 @@ describe("BlDatepicker", () => {
385385
expect(focusSpy.called).to.be.true;
386386
});
387387

388+
it("should call setDatePickerInput when _selectedDates changes", async () => {
389+
const setDatePickerInputSpy = sinon.spy(element, "setDatePickerInput");
390+
391+
element.value = [new Date(2025,0,10)];
392+
await elementUpdated(element);
393+
394+
expect(setDatePickerInputSpy).to.have.been.calledOnceWith(element._selectedDates);
395+
});
396+
388397
});

src/components/datepicker/bl-datepicker.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CSSResultGroup, html, TemplateResult } from "lit";
1+
import { CSSResultGroup, html, PropertyValues, TemplateResult } from "lit";
22
import { customElement, property, query, state } from "lit/decorators.js";
33
import { BlCalendar, BlPopover } from "../../baklava";
44
import DatepickerCalendarMixin from "../../mixins/datepicker-calendar-mixin/datepicker-calendar-mixin";
@@ -197,6 +197,12 @@ export default class BlDatepicker extends DatepickerCalendarMixin {
197197
}
198198
}
199199

200+
updated(changedProperties: PropertyValues) {
201+
if (changedProperties.has("_selectedDates")) {
202+
this.setDatePickerInput(this._selectedDates);
203+
}
204+
}
205+
200206
disconnectedCallback() {
201207
super.disconnectedCallback();
202208
this._calendarEl?.removeEventListener("mousedown", this._onCalendarMouseDown);

0 commit comments

Comments
 (0)