Skip to content

Commit aa3a4e5

Browse files
fix(datetime): ensures no orphan timeout exists
1 parent 6b853c5 commit aa3a4e5

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed

core/src/components/datetime/datetime.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,10 +1096,7 @@ export class Datetime implements ComponentInterface {
10961096
this.clearFocusVisible();
10971097
this.clearFocusVisible = undefined;
10981098
}
1099-
if (this.loadTimeout) {
1100-
clearTimeout(this.loadTimeout);
1101-
this.loadTimeout = undefined;
1102-
}
1099+
this.loadTimeoutCleanup();
11031100
}
11041101

11051102
/**
@@ -1150,6 +1147,13 @@ export class Datetime implements ComponentInterface {
11501147
});
11511148
};
11521149

1150+
private loadTimeoutCleanup = () => {
1151+
if (this.loadTimeout) {
1152+
clearTimeout(this.loadTimeout);
1153+
this.loadTimeout = undefined;
1154+
}
1155+
};
1156+
11531157
componentDidLoad() {
11541158
const { el, intersectionTrackerRef } = this;
11551159

@@ -1197,7 +1201,10 @@ export class Datetime implements ComponentInterface {
11971201
* we still initialize listeners and mark the component as ready.
11981202
*
11991203
* We schedule this after everything has had a chance to run.
1204+
*
1205+
* We also clean up the load timeout to ensure that we don't have multiple timeouts running.
12001206
*/
1207+
this.loadTimeoutCleanup();
12011208
this.loadTimeout = setTimeout(() => {
12021209
this.ensureReadyIfVisible();
12031210
}, 100);

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

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -270,39 +270,6 @@ configs().forEach(({ title, screenshot, config }) => {
270270
const datetime = page.locator('ion-datetime');
271271
await expect(datetime).toHaveScreenshot(screenshot(`datetime-footer-custom-buttons`));
272272
});
273-
test('should only have one active month option after changing month twice', async ({ page }) => {
274-
await page.setContent(
275-
`
276-
<ion-datetime value="2022-05-03"></ion-datetime>
277-
`,
278-
config
279-
);
280-
281-
await page.locator('.datetime-ready').waitFor();
282-
283-
const nextMonthButton = page.locator('ion-datetime .calendar-next-prev ion-button').nth(1);
284-
const monthYearButton = page.locator('ion-datetime .calendar-month-year');
285-
286-
await monthYearButton.click();
287-
await page.waitForChanges();
288-
await monthYearButton.click();
289-
await page.waitForChanges();
290-
await nextMonthButton.click();
291-
await page.waitForChanges();
292-
await page.waitForTimeout(2000);
293-
await monthYearButton.click();
294-
await page.waitForChanges();
295-
await monthYearButton.click();
296-
await page.waitForChanges();
297-
await nextMonthButton.click();
298-
await page.waitForChanges();
299-
await page.waitForTimeout(2000);
300-
await monthYearButton.click();
301-
await page.waitForChanges();
302-
303-
const selectedMonthOptions = page.locator('.month-column ion-picker-column-option.option-active');
304-
await expect(selectedMonthOptions).toHaveCount(1);
305-
});
306273
});
307274
});
308275

@@ -382,6 +349,40 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
382349
});
383350
});
384351

352+
/**
353+
* This behavior does not differ across
354+
* modes/directions.
355+
*/
356+
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ config }) => {
357+
test('datetime: month picker selection', async ({ page }) => {
358+
await page.setContent(
359+
`
360+
<ion-datetime value="2022-05-03"></ion-datetime>
361+
`,
362+
config
363+
);
364+
365+
await page.locator('.datetime-ready').waitFor();
366+
367+
const nextMonthButton = page.locator('ion-datetime .calendar-next-prev ion-button').nth(1);
368+
const monthYearButton = page.locator('ion-datetime .calendar-month-year');
369+
370+
await expect(monthYearButton).toHaveText(/May 2022/);
371+
372+
await nextMonthButton.click();
373+
await expect(monthYearButton).toHaveText(/June 2022/);
374+
375+
await nextMonthButton.click();
376+
await expect(monthYearButton).toHaveText(/July 2022/);
377+
378+
await monthYearButton.click();
379+
await page.waitForChanges();
380+
381+
const selectedMonthOptions = page.locator('.month-column ion-picker-column-option.option-active');
382+
await expect(selectedMonthOptions).toHaveCount(1);
383+
});
384+
});
385+
385386
/**
386387
* This behavior does not differ across
387388
* modes/directions.

0 commit comments

Comments
 (0)