Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datetime): clear button clears the selected date #26264

Merged
merged 2 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/src/components/datetime/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,13 @@ export class Datetime implements ComponentInterface {
ampm,
};
}
} else {
/**
* Reset the active parts if the value is not set.
* This will clear the selected calendar day when
* performing a clear action or using the reset() method.
*/
this.activeParts = [];
}
};

Expand Down
28 changes: 28 additions & 0 deletions core/src/components/datetime/test/basic/datetime.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,31 @@ test.describe('datetime: RTL set on component', () => {
await expect(nextPrevIcons.last()).toHaveClass(/flip-rtl/);
});
});

test.describe('datetime: clear button', () => {
test('should clear the active calendar day', async ({ page, skip }, testInfo) => {
skip.rtl();
skip.mode('md');

testInfo.annotations.push({
type: 'issue',
description: 'https://github.com/ionic-team/ionic-framework/issues/26258',
});

await page.setContent(`
<ion-datetime value="2022-11-10" show-clear-button="true"></ion-datetime>
`);

await page.waitForSelector('.datetime-ready');

const selectedDay = page.locator('ion-datetime .calendar-day-active');

await expect(selectedDay).toHaveText('10');

await page.click('ion-datetime #clear-button');

await page.waitForChanges();

await expect(selectedDay).toHaveCount(0);
});
});