Skip to content

Commit

Permalink
feat(datepicker): fix clear dates event bug (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
dilandoogan authored Jan 7, 2025
1 parent cda4b34 commit 004e769
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/components/datepicker/bl-datepicker.test.ts
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions src/components/datepicker/bl-datepicker.ts
Original file line number Diff line number Diff line change
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 @@ -242,7 +242,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

0 comments on commit 004e769

Please sign in to comment.