Skip to content

Commit

Permalink
fix(date-dropdown): updated the current date when the props are chang…
Browse files Browse the repository at this point in the history
…ed (#1139)

Co-authored-by: Demirci <[email protected]>
Co-authored-by: Daniel Leroux <[email protected]>
Co-authored-by: Lukas Maurer <[email protected]>
  • Loading branch information
4 people authored Apr 3, 2024
1 parent b7a56fe commit 99886e0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-insects-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@siemens/ix": patch
---

fix(core/date-dropdown): update the date when the props are changed
23 changes: 13 additions & 10 deletions packages/core/src/components/date-dropdown/date-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -196,3 +196,22 @@ test.describe('date dropdown tests', () => {
});
});
});

test('set date from a button', async ({ mount, page }) => {
await mount(
`<ix-date-dropdown from="2024/02/16"></ix-date-dropdown><ix-button id="set-tomorrow"></ix-button>`
);
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/);
});

0 comments on commit 99886e0

Please sign in to comment.