From 004e7696158381e6f8bcb4346a0d68d9e0880c00 Mon Sep 17 00:00:00 2001 From: dilandoogan <147757889+dilandoogan@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:59:26 +0300 Subject: [PATCH] feat(datepicker): fix clear dates event bug (#982) --- src/components/datepicker/bl-datepicker.test.ts | 9 +++++++++ src/components/datepicker/bl-datepicker.ts | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/datepicker/bl-datepicker.test.ts b/src/components/datepicker/bl-datepicker.test.ts index 36a52247..9e0c6528 100644 --- a/src/components/datepicker/bl-datepicker.test.ts +++ b/src/components/datepicker/bl-datepicker.test.ts @@ -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(""); }); diff --git a/src/components/datepicker/bl-datepicker.ts b/src/components/datepicker/bl-datepicker.ts index b77eabbe..b3f8942a 100644 --- a/src/components/datepicker/bl-datepicker.ts +++ b/src/components/datepicker/bl-datepicker.ts @@ -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() { @@ -242,7 +242,7 @@ export default class BlDatepicker extends DatepickerCalendarMixin { variant="tertiary" kind="neutral" icon="close" - @click=${() => this.clearDatepicker()} + @click=${this.clearDatepicker} >
` : "";