fix(datetime): header renders correct date (#26120)

resolves #26116
This commit is contained in:
Liam DeBeasi
2022-10-13 11:17:21 -05:00
committed by GitHub
parent 256b03f12a
commit 04df45a443
2 changed files with 26 additions and 2 deletions

View File

@ -2112,11 +2112,11 @@ export class Datetime implements ComponentInterface {
return;
}
const { activeParts, titleSelectedDatesFormatter } = this;
const { activeParts, multiple, titleSelectedDatesFormatter } = this;
const isArray = Array.isArray(activeParts);
let headerText: string;
if (isArray && activeParts.length !== 1) {
if (multiple && isArray && activeParts.length !== 1) {
headerText = `${activeParts.length} days`; // default/fallback for multiple selection
if (titleSelectedDatesFormatter !== undefined) {
try {

View File

@ -189,4 +189,28 @@ test.describe('datetime: multiple date selection (functionality)', () => {
await juneButtons.nth(0).click();
await expect(header).toHaveText('Selected: 0');
});
test('header text should render default date when multiple="false"', async ({ page }) => {
await page.setContent(`
<ion-datetime locale="en-US" show-default-title="true"></ion-datetime>
<script>
const mockToday = '2022-10-10T16:22';
Date = class extends Date {
constructor(...args) {
if (args.length === 0) {
super(mockToday)
} else {
super(...args);
}
}
}
</script>
`);
await page.waitForSelector(`.datetime-ready`);
const datetime = page.locator('ion-datetime');
const header = datetime.locator('.datetime-selected-date');
await expect(header).toHaveText('Mon, Oct 10');
});
});