Skip to content

Commit

Permalink
Merge branch 'next' into feat/radio-a11y
Browse files Browse the repository at this point in the history
  • Loading branch information
erbilnas authored Jan 8, 2025
2 parents e3aaa7f + 33dd9a4 commit 457fba2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/calendar/bl-calendar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ describe("bl-calendar", () => {

const setNextCalendarViewSpy = sinon.spy(element, "setNextCalendarView");

element.handleDate(new Date(2024, 2, 15));
element.handleDate(new Date(element.today.getFullYear()+1,2,15));

expect(setNextCalendarViewSpy).to.have.been.called;

Expand Down
20 changes: 19 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 @@ -95,11 +95,20 @@ describe("BlDatepicker", () => {
element._selectedDates = [new Date(2023, 1, 1)];
await element.updateComplete;

element.addEventListener("bl-datepicker-change", (event) => {
const customEvent = event as CustomEvent;

expect(customEvent).to.exist;
expect(customEvent.detail).to.deep.equal([]);

});

const clearButton = element.shadowRoot?.querySelector("bl-button") as BlButton;

clearButton?.click();
await element.updateComplete;


expect(element._selectedDates).to.deep.equal([]);
expect(element._inputValue).to.equal("");
});
Expand Down Expand Up @@ -376,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);
});

});
12 changes: 9 additions & 3 deletions 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 @@ -147,10 +147,10 @@ export default class BlDatepicker extends DatepickerCalendarMixin {
}

clearDatepicker() {
this._calendarEl.handleClearSelectedDates();
this._selectedDates = [];
this._inputValue = "";
this._floatingDateCount = 0;
this._calendarEl.handleClearSelectedDates();
}

openPopover() {
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 Expand Up @@ -242,7 +248,7 @@ export default class BlDatepicker extends DatepickerCalendarMixin {
variant="tertiary"
kind="neutral"
icon="close"
@click=${() => this.clearDatepicker()}
@click=${this.clearDatepicker}
></bl-button>
<div class="action-divider"></div>`
: "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default class DatepickerCalendarMixin extends LitElement {

@property({
attribute: "disabled-dates",
type: Array,
reflect: true,
})
set disabledDates(disabledDates: Date[] | string) {
Expand Down

0 comments on commit 457fba2

Please sign in to comment.