Skip to content

Commit

Permalink
feat(datepicker): when datepicker value updated datepicker input valu… (
Browse files Browse the repository at this point in the history
#983)

…e should also updated
  • Loading branch information
dilandoogan authored Jan 8, 2025
1 parent 004e769 commit 33dd9a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/components/datepicker/bl-datepicker.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { aTimeout, expect, fixture, html } from "@open-wc/testing";
import { aTimeout, elementUpdated, expect, fixture, html } from "@open-wc/testing";
import { BlButton, BlDatePicker } from "../../baklava";
import { CALENDAR_TYPES } from "../calendar/bl-calendar.constant";
import sinon from "sinon";
Expand Down Expand Up @@ -385,4 +385,13 @@ describe("BlDatepicker", () => {
expect(focusSpy.called).to.be.true;
});

it("should call setDatePickerInput when _selectedDates changes", async () => {
const setDatePickerInputSpy = sinon.spy(element, "setDatePickerInput");

element.value = [new Date(2025,0,10)];
await elementUpdated(element);

expect(setDatePickerInputSpy).to.have.been.calledOnceWith(element._selectedDates);
});

});
8 changes: 7 additions & 1 deletion src/components/datepicker/bl-datepicker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CSSResultGroup, html, TemplateResult } from "lit";
import { CSSResultGroup, html, PropertyValues, TemplateResult } from "lit";
import { customElement, property, query, state } from "lit/decorators.js";
import { BlCalendar, BlPopover } from "../../baklava";
import DatepickerCalendarMixin from "../../mixins/datepicker-calendar-mixin/datepicker-calendar-mixin";
Expand Down Expand Up @@ -197,6 +197,12 @@ export default class BlDatepicker extends DatepickerCalendarMixin {
}
}

updated(changedProperties: PropertyValues) {
if (changedProperties.has("_selectedDates")) {
this.setDatePickerInput(this._selectedDates);
}
}

disconnectedCallback() {
super.disconnectedCallback();
this._calendarEl?.removeEventListener("mousedown", this._onCalendarMouseDown);
Expand Down

0 comments on commit 33dd9a4

Please sign in to comment.