Skip to content
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
9 changes: 9 additions & 0 deletions core/src/components/datetime/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,15 @@ export class Datetime implements ComponentInterface {

this.destroyInteractionListeners();

/**
* When datetime is hidden, we need to make sure that
* the month/year picker is closed. Otherwise,
* it will be open when the datetime re-appears
* and the scroll area of the calendar grid will be 0.
* As a result, the wrong month will be shown.
*/
this.showMonthAndYear = false;

writeTask(() => {
this.el.classList.remove('datetime-ready');
});
Expand Down
31 changes: 31 additions & 0 deletions core/src/components/datetime/test/basic/datetime.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,34 @@ test.describe('datetime: swiping', () => {
}
});
});

test.describe('datetime: visibility', () => {
test('should reset month/year interface when hiding datetime', async ({ page, skip }) => {
skip.rtl();
skip.mode('md');

await page.setContent(`
<ion-datetime></ion-datetime>
`);

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

const monthYearButton = page.locator('ion-datetime .calendar-month-year');
const monthYearInterface = page.locator('ion-datetime .datetime-year');
const datetime = page.locator('ion-datetime');

await monthYearButton.click();
await page.waitForChanges();

await expect(monthYearInterface).toBeVisible();

await datetime.evaluate((el: HTMLIonDatetimeElement) => el.style.setProperty('display', 'none'));
await expect(datetime).toBeHidden();

await datetime.evaluate((el: HTMLIonDatetimeElement) => el.style.removeProperty('display'));
await expect(datetime).toBeVisible();

// month/year interface should be reset
await expect(monthYearInterface).toBeHidden();
});
});