diff --git a/.changeset/orange-insects-pull.md b/.changeset/orange-insects-pull.md new file mode 100644 index 0000000000..6cc8fa909f --- /dev/null +++ b/.changeset/orange-insects-pull.md @@ -0,0 +1,5 @@ +--- +"@siemens/ix": patch +--- + +fix(core/date-dropdown): update the date when the props are changed diff --git a/packages/core/src/components/date-dropdown/date-dropdown.tsx b/packages/core/src/components/date-dropdown/date-dropdown.tsx index 943c506887..6eb5e12842 100644 --- a/packages/core/src/components/date-dropdown/date-dropdown.tsx +++ b/packages/core/src/components/date-dropdown/date-dropdown.tsx @@ -95,6 +95,9 @@ export class DateDropdown { @Watch('from') onDateRangeIdChange() { this.onRangeListSelect(this.dateRangeId); + this.updateCurrentDate(); + this.setDateRangeSelection(this.dateRangeId); + this.onDateSelect({ from: this.currentRangeValue.from, to: this.currentRangeValue.to, @@ -186,11 +189,7 @@ export class DateDropdown { if (isCustomRange && this.customRangeAllowed) { this.selectedDateRangeId = 'custom'; - this.currentRangeValue = { - id: this.selectedDateRangeId, - from: this.from, - to: this.to, - }; + this.updateCurrentDate(); return; } @@ -201,16 +200,20 @@ export class DateDropdown { ); this.selectedDateRangeId = 'custom'; - this.currentRangeValue = { - id: this.selectedDateRangeId, - from: this.from, - to: this.to, - }; + this.updateCurrentDate(); return; } } + private updateCurrentDate() { + this.currentRangeValue = { + id: this.selectedDateRangeId, + from: this.from, + to: this.to, + }; + } + private onDateSelect( rangeValue: { from: string; to: string; id: string }, preserveDropdown = true diff --git a/packages/core/src/components/date-dropdown/test/date-dropdown.ct.ts b/packages/core/src/components/date-dropdown/test/date-dropdown.ct.ts index 874801d393..9e4b0c9982 100644 --- a/packages/core/src/components/date-dropdown/test/date-dropdown.ct.ts +++ b/packages/core/src/components/date-dropdown/test/date-dropdown.ct.ts @@ -178,7 +178,7 @@ test.describe('date dropdown tests', () => { }); test('check initial date', async ({ page }) => { - const dateDropDownButton = page.locator('ix-date-dropdown'); + const dateDropDownButton = page.locator(DATE_DROPDOWN_SELECTOR); await expect(dateDropDownButton).toHaveClass(/hydrated/); const initialSetDate = await dateDropDownButton.evaluate( @@ -196,3 +196,22 @@ test.describe('date dropdown tests', () => { }); }); }); + +test('set date from a button', async ({ mount, page }) => { + await mount( + `` + ); + const dateDropdown = page.locator(DATE_DROPDOWN_SELECTOR); + const setButton = page.locator('#set-tomorrow'); + await expect(dateDropdown).toHaveClass(/hydrated/); + + await setButton.click(); + + await dateDropdown.evaluate((el: HTMLIxDateDropdownElement) => { + el.from = '2024/02/17'; + el.to = '2024/02/27'; + return el.getDateRange(); + }); + const button = dateDropdown.locator('[data-date-dropdown-trigger]'); + await expect(button).toHaveText(/2024\/02\/17 \- 2024\/02\/27/); +});