Skip to content

Commit f9ab9b5

Browse files
authored
fix(datetime): closing time picker no longer changes month (#25478)
resolves #25438
1 parent 1a8d23d commit f9ab9b5

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,35 @@ import { expect } from '@playwright/test';
22
import type { E2EPage } from '@utils/test/playwright';
33
import { test } from '@utils/test/playwright';
44

5+
test.describe('datetime: closing time popover', () => {
6+
test('it should not change months', async ({ page }) => {
7+
test.info().annotations.push({
8+
type: 'issue',
9+
description: 'https://github.com/ionic-team/ionic-framework/issues/25438',
10+
});
11+
12+
await page.setContent(`
13+
<ion-datetime></ion-datetime>
14+
`);
15+
16+
const ionPopoverDidPresent = await page.spyOnEvent('ionPopoverDidPresent');
17+
const ionPopoverDidDismiss = await page.spyOnEvent('ionPopoverDidDismiss');
18+
const timeButton = page.locator('.time-body');
19+
const calendarMonthYear = page.locator('ion-datetime .calendar-month-year');
20+
const currentMonthAndYear = await calendarMonthYear.evaluate((el: HTMLElement) => el.innerText);
21+
22+
await timeButton.click();
23+
await ionPopoverDidPresent.next();
24+
25+
await page.keyboard.press('Escape');
26+
27+
await ionPopoverDidDismiss.next();
28+
await page.waitForChanges();
29+
30+
expect(calendarMonthYear).toHaveText(currentMonthAndYear);
31+
});
32+
});
33+
534
test.describe('datetime: selecting a day', () => {
635
const testHighlight = async (page: E2EPage, datetimeID: string) => {
736
const today = new Date();

core/src/utils/overlays.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,14 @@ export const createOverlay = <T extends HTMLIonOverlayElement>(
8484

8585
const focusableQueryString =
8686
'[tabindex]:not([tabindex^="-"]), input:not([type=hidden]):not([tabindex^="-"]), textarea:not([tabindex^="-"]), button:not([tabindex^="-"]), select:not([tabindex^="-"]), .ion-focusable:not([tabindex^="-"])';
87-
const innerFocusableQueryString = 'input:not([type=hidden]), textarea, button, select';
8887

8988
export const focusFirstDescendant = (ref: Element, overlay: HTMLIonOverlayElement) => {
9089
let firstInput = ref.querySelector(focusableQueryString) as HTMLElement | null;
9190

9291
const shadowRoot = firstInput?.shadowRoot;
9392
if (shadowRoot) {
9493
// If there are no inner focusable elements, just focus the host element.
95-
firstInput = shadowRoot.querySelector(innerFocusableQueryString) || firstInput;
94+
firstInput = shadowRoot.querySelector(focusableQueryString) || firstInput;
9695
}
9796

9897
if (firstInput) {
@@ -112,7 +111,7 @@ const focusLastDescendant = (ref: Element, overlay: HTMLIonOverlayElement) => {
112111
const shadowRoot = lastInput?.shadowRoot;
113112
if (shadowRoot) {
114113
// If there are no inner focusable elements, just focus the host element.
115-
lastInput = shadowRoot.querySelector(innerFocusableQueryString) || lastInput;
114+
lastInput = shadowRoot.querySelector(focusableQueryString) || lastInput;
116115
}
117116

118117
if (lastInput) {
@@ -460,7 +459,7 @@ const focusPreviousElementOnDismiss = async (overlayEl: any) => {
460459
const shadowRoot = previousElement?.shadowRoot;
461460
if (shadowRoot) {
462461
// If there are no inner focusable elements, just focus the host element.
463-
previousElement = shadowRoot.querySelector(innerFocusableQueryString) || previousElement;
462+
previousElement = shadowRoot.querySelector(focusableQueryString) || previousElement;
464463
}
465464

466465
await overlayEl.onDidDismiss();

0 commit comments

Comments
 (0)