Skip to content

Commit 9fc848a

Browse files
fix(datetime): scroll failing for adjacent days on ios (#31033)
Issue number: resolves internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> When the user swipes to a previous month that has adjacent days and selects one of the adjacent days from a previous month, the datetime selects the day but fails to scroll to the previous month. When a user clicks on a previous adjacent day after swiping the month, the calendar scrolls to the previous month. The same is applied to the next month. - [ ] Yes - [x] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> The previous behavior was only reproducible on iOS real devices.
1 parent 24861e5 commit 9fc848a

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

core/src/components/datetime/datetime.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,9 +1550,11 @@ export class Datetime implements ComponentInterface {
15501550
return;
15511551
}
15521552

1553+
const left = (prevMonth as HTMLElement).offsetWidth * 2;
1554+
15531555
calendarBodyRef.scrollTo({
15541556
top: 0,
1555-
left: 0,
1557+
left: left * (isRTL(this.el) ? 1 : -1),
15561558
behavior: 'smooth',
15571559
});
15581560
};

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ configs({ modes: ['ios', 'md', 'ionic-md'], directions: ['ltr'] }).forEach(({ ti
5555
const datetime = page.locator('#display');
5656
await expect(datetime).toHaveScreenshot(screenshot(`datetime-show-adjacent-days-display`));
5757
});
58+
});
59+
});
5860

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

0 commit comments

Comments
 (0)