Skip to content

Commit f24fe2e

Browse files
fix(datetime): multiple month selected and flakiness display
1 parent 34effe8 commit f24fe2e

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

core/src/components/datetime/datetime.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,9 @@ export class Datetime implements ComponentInterface {
10861086

10871087
connectedCallback() {
10881088
this.clearFocusVisible = startFocusVisible(this.el).destroy;
1089+
this.loadTimeout = setTimeout(() => {
1090+
this.ensureReadyIfVisible();
1091+
}, 100);
10891092
}
10901093

10911094
disconnectedCallback() {
@@ -1095,6 +1098,7 @@ export class Datetime implements ComponentInterface {
10951098
}
10961099
if (this.loadTimeout) {
10971100
clearTimeout(this.loadTimeout);
1101+
this.loadTimeout = undefined;
10981102
}
10991103
}
11001104

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,29 @@ 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 nextMonthButton.click();
287+
await nextMonthButton.click();
288+
await page.waitForChanges();
289+
290+
await monthYearButton.click();
291+
await page.waitForChanges();
292+
293+
const selectedMonthOptions = page.locator('.month-column ion-picker-column-option.option-active');
294+
await expect(selectedMonthOptions).toHaveCount(1);
295+
});
273296
});
274297
});
275298

core/src/components/picker-column/picker-column.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ComponentInterface, EventEmitter } from '@stencil/core';
22
import { Component, Element, Event, Host, Method, Prop, State, Watch, h } from '@stencil/core';
33
import { doc } from '@utils/browser';
4-
import { getElementRoot, raf } from '@utils/helpers';
4+
import { raf } from '@utils/helpers';
55
import { hapticSelectionChanged, hapticSelectionEnd, hapticSelectionStart } from '@utils/native/haptic';
66
import { isPlatform } from '@utils/platform';
77
import { createColorClasses } from '@utils/theme';
@@ -122,9 +122,7 @@ export class PickerColumn implements ComponentInterface {
122122
* Because this initial call to scrollActiveItemIntoView has to fire before
123123
* the scroll listener is set up, we need to manage the active class manually.
124124
*/
125-
const oldActive = getElementRoot(el).querySelector<HTMLIonPickerColumnOptionElement>(
126-
`.${PICKER_ITEM_ACTIVE_CLASS}`
127-
);
125+
const oldActive = el.querySelector<HTMLIonPickerColumnOptionElement>(`.${PICKER_ITEM_ACTIVE_CLASS}`);
128126
if (oldActive) {
129127
this.setPickerItemActiveState(oldActive, false);
130128
}

0 commit comments

Comments
 (0)