Skip to content

Commit 28c4acb

Browse files
fix(datetime): change approach and added test for use case
1 parent f13ceda commit 28c4acb

File tree

2 files changed

+63
-5
lines changed

2 files changed

+63
-5
lines changed

core/src/components/datetime/datetime.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,13 @@ export class Datetime implements ComponentInterface {
15251525
return;
15261526
}
15271527

1528-
nextMonth.scrollIntoView({ behavior: 'smooth' });
1528+
const left = (nextMonth as HTMLElement).offsetWidth * 2;
1529+
1530+
calendarBodyRef.scrollTo({
1531+
top: 0,
1532+
left: left * (isRTL(this.el) ? -1 : 1),
1533+
behavior: 'smooth',
1534+
});
15291535
};
15301536

15311537
private prevMonth = () => {
@@ -1538,7 +1544,14 @@ export class Datetime implements ComponentInterface {
15381544
if (!prevMonth) {
15391545
return;
15401546
}
1541-
prevMonth.scrollIntoView({ behavior: 'smooth' });
1547+
1548+
const left = (prevMonth as HTMLElement).offsetWidth * 2;
1549+
1550+
calendarBodyRef.scrollTo({
1551+
top: 0,
1552+
left: left * (isRTL(this.el) ? -1 : 1),
1553+
behavior: 'smooth',
1554+
});
15421555
};
15431556

15441557
private toggleMonthAndYearView = () => {

core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { expect } from '@playwright/test';
22
import { configs, test } from '@utils/test/playwright';
33

4-
/**
5-
* This behavior does not vary across directions
6-
*/
74
configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
85
test.describe(title('datetime: show adjacent days'), () => {
96
test('should not have visual regressions', async ({ page }) => {
@@ -54,7 +51,11 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
5451
const datetime = page.locator('#display');
5552
await expect(datetime).toHaveScreenshot(screenshot(`datetime-show-adjacent-days-display`));
5653
});
54+
});
55+
});
5756

57+
configs({ directions: ['ltr', 'rtl'] }).forEach(({ title, config }) => {
58+
test.describe(title('datetime: show adjacent days'), () => {
5859
test('should return the same date format on current month days and on adjacent days', async ({ page }) => {
5960
await page.setContent(
6061
`
@@ -124,5 +125,49 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
124125
value: '2022-11-22T16:22:00',
125126
});
126127
});
128+
129+
test('should navigate to previous month via swipe and then select adjacent day from prior month', async ({ page }) => {
130+
await page.setContent(
131+
`
132+
<ion-datetime show-adjacent-days="true" value="2026-02-14T16:22:00.000Z" presentation="date"></ion-datetime>
133+
`,
134+
config
135+
);
136+
137+
// Wait for the datetime to be ready.
138+
await page.locator('.datetime-ready').waitFor();
139+
const ionChange = await page.spyOnEvent('ionChange');
140+
const calendarMonthYear = page.locator('ion-datetime .calendar-month-year');
141+
const calendarBody = page.locator('ion-datetime .calendar-body');
142+
143+
// Wait for the month to be visible.
144+
await expect(calendarMonthYear).toHaveText('February 2026');
145+
146+
// Scroll to the previous month.
147+
await calendarBody.evaluate((el: HTMLElement) => {
148+
const rtl = document.documentElement.dir === 'rtl';
149+
el.scrollLeft += rtl ? el.clientWidth * 2 : -el.clientWidth * 2;
150+
});
151+
152+
// Wait for the month to change.
153+
await page.waitForChanges();
154+
await expect(calendarMonthYear).toHaveText('January 2026');
155+
156+
// Select the adjacent day from the prior month.
157+
const dec31Adjacent = page.locator(
158+
'.calendar-day-adjacent-day[data-month="12"][data-year="2025"][data-day="31"]'
159+
);
160+
await dec31Adjacent.click();
161+
162+
// Wait for the month to change.
163+
await page.waitForChanges();
164+
165+
// Wait for the month to be visible.
166+
await expect(calendarMonthYear).toHaveText('December 2025');
167+
await ionChange.next();
168+
await expect(ionChange).toHaveReceivedEventDetail({
169+
value: '2025-12-31T16:22:00',
170+
});
171+
});
127172
});
128173
});

0 commit comments

Comments
 (0)