fix(datetime): close month/year picker when hidden (#25789)

resolves #25787
This commit is contained in:
Liam DeBeasi
2022-08-22 10:15:02 -05:00
committed by GitHub
parent 08dd3e277b
commit 3b211b60fd
2 changed files with 40 additions and 0 deletions

View File

@@ -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');
});

View File

@@ -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();
});
});