Skip to content

Commit 9216744

Browse files
authored
fix(datetime): clear button clears the selected date (#26264)
Resolves #26258
1 parent 627d654 commit 9216744

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

core/src/components/datetime/datetime.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,13 @@ export class Datetime implements ComponentInterface {
12201220
ampm,
12211221
};
12221222
}
1223+
} else {
1224+
/**
1225+
* Reset the active parts if the value is not set.
1226+
* This will clear the selected calendar day when
1227+
* performing a clear action or using the reset() method.
1228+
*/
1229+
this.activeParts = [];
12231230
}
12241231
};
12251232

core/src/components/datetime/test/basic/datetime.e2e.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,31 @@ test.describe('datetime: RTL set on component', () => {
327327
await expect(nextPrevIcons.last()).toHaveClass(/flip-rtl/);
328328
});
329329
});
330+
331+
test.describe('datetime: clear button', () => {
332+
test('should clear the active calendar day', async ({ page, skip }, testInfo) => {
333+
skip.rtl();
334+
skip.mode('md');
335+
336+
testInfo.annotations.push({
337+
type: 'issue',
338+
description: 'https://github.com/ionic-team/ionic-framework/issues/26258',
339+
});
340+
341+
await page.setContent(`
342+
<ion-datetime value="2022-11-10" show-clear-button="true"></ion-datetime>
343+
`);
344+
345+
await page.waitForSelector('.datetime-ready');
346+
347+
const selectedDay = page.locator('ion-datetime .calendar-day-active');
348+
349+
await expect(selectedDay).toHaveText('10');
350+
351+
await page.click('ion-datetime #clear-button');
352+
353+
await page.waitForChanges();
354+
355+
await expect(selectedDay).toHaveCount(0);
356+
});
357+
});

0 commit comments

Comments
 (0)