Skip to content

Commit a31502b

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

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-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: 50 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,51 @@ 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 ({
130+
page,
131+
}) => {
132+
await page.setContent(
133+
`
134+
<ion-datetime show-adjacent-days="true" value="2026-02-14T16:22:00.000Z" presentation="date"></ion-datetime>
135+
`,
136+
config
137+
);
138+
139+
// Wait for the datetime to be ready.
140+
await page.locator('.datetime-ready').waitFor();
141+
const ionChange = await page.spyOnEvent('ionChange');
142+
const calendarMonthYear = page.locator('ion-datetime .calendar-month-year');
143+
const calendarBody = page.locator('ion-datetime .calendar-body');
144+
145+
// Wait for the month to be visible.
146+
await expect(calendarMonthYear).toHaveText('February 2026');
147+
148+
// Scroll to the previous month.
149+
await calendarBody.evaluate((el: HTMLElement) => {
150+
const rtl = document.documentElement.dir === 'rtl';
151+
el.scrollLeft += rtl ? el.clientWidth * 2 : -el.clientWidth * 2;
152+
});
153+
154+
// Wait for the month to change.
155+
await page.waitForChanges();
156+
await expect(calendarMonthYear).toHaveText('January 2026');
157+
158+
// Select the adjacent day from the prior month.
159+
const dec31Adjacent = page.locator(
160+
'.calendar-day-adjacent-day[data-month="12"][data-year="2025"][data-day="31"]'
161+
);
162+
await dec31Adjacent.click();
163+
164+
// Wait for the month to change.
165+
await page.waitForChanges();
166+
167+
// Wait for the month to be visible.
168+
await expect(calendarMonthYear).toHaveText('December 2025');
169+
await ionChange.next();
170+
await expect(ionChange).toHaveReceivedEventDetail({
171+
value: '2025-12-31T16:22:00',
172+
});
173+
});
127174
});
128175
});

0 commit comments

Comments
 (0)