Skip to content

Commit a35f8a9

Browse files
authored
fix(datetime): respect config animated setting when paging month calendar (#31227)
Issue number: resolves #30484 --------- ## What is the current behavior? Paging through the month calendar in an <IonDatetime> always scrolls smoothly regardless of the `animated` property in global config ## What is the new behavior? Paging will scroll instantly (no animation) if `animated` is false, otherwise the previous smooth scroll behavior persists ## Does this introduce a breaking change? - [ ] Yes - [x] No
1 parent 044f358 commit a35f8a9

2 files changed

Lines changed: 85 additions & 2 deletions

File tree

core/src/components/datetime/datetime.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { isRTL } from '@utils/rtl';
88
import { createColorClasses } from '@utils/theme';
99
import { caretDownSharp, caretUpSharp, chevronBack, chevronDown, chevronForward } from 'ionicons/icons';
1010

11+
import { config } from '../../global/config';
1112
import { getIonMode } from '../../global/ionic-global';
1213
import type { Color, Mode, StyleEventDetail } from '../../interface';
1314

@@ -1567,10 +1568,11 @@ export class Datetime implements ComponentInterface {
15671568

15681569
const left = (nextMonth as HTMLElement).offsetWidth * 2;
15691570

1571+
const scrollMode = config.getBoolean('animated', true) ? 'smooth' : 'instant';
15701572
calendarBodyRef.scrollTo({
15711573
top: 0,
15721574
left: left * (isRTL(this.el) ? -1 : 1),
1573-
behavior: 'smooth',
1575+
behavior: scrollMode,
15741576
});
15751577
};
15761578

@@ -1587,10 +1589,11 @@ export class Datetime implements ComponentInterface {
15871589

15881590
const left = (prevMonth as HTMLElement).offsetWidth * 2;
15891591

1592+
const scrollMode = config.getBoolean('animated', true) ? 'smooth' : 'instant';
15901593
calendarBodyRef.scrollTo({
15911594
top: 0,
15921595
left: left * (isRTL(this.el) ? 1 : -1),
1593-
behavior: 'smooth',
1596+
behavior: scrollMode,
15941597
});
15951598
};
15961599

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,3 +816,83 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
816816
});
817817
});
818818
});
819+
820+
/**
821+
* This behavior does not differ across
822+
* modes/directions.
823+
*/
824+
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
825+
test.describe(title('datetime: animated'), () => {
826+
test('next month button should instantly replace month view when animations are disabled', async ({ page }) => {
827+
test.info().annotations.push({
828+
type: 'issue',
829+
description: 'https://github.com/ionic-team/ionic-framework/issues/30484',
830+
});
831+
832+
await page.addInitScript(() => {
833+
(window as any).__scrollToCalls = [];
834+
const original = Element.prototype.scrollTo;
835+
Element.prototype.scrollTo = function (this: Element, ...args: any[]) {
836+
if (this.classList?.contains('calendar-body')) {
837+
(window as any).__scrollToCalls.push(args[0]);
838+
}
839+
return (original as any).apply(this, args);
840+
};
841+
});
842+
843+
await page.setContent(
844+
`
845+
<script>window.Ionic = {config: {animated: false}};</script>
846+
<ion-datetime value="2026-06-19T16:08:25.697Z"></ion-datetime>
847+
`,
848+
config
849+
);
850+
await page.locator('.datetime-ready').waitFor();
851+
852+
const nextMonthButton = page.locator('ion-datetime .calendar-next-prev ion-button').nth(1);
853+
await nextMonthButton.click();
854+
await page.waitForChanges();
855+
856+
const scrollCalls = await page.evaluate(() => (window as any).__scrollToCalls);
857+
858+
expect(scrollCalls.length).toBeGreaterThan(0);
859+
expect(scrollCalls[0].behavior).toBe('instant');
860+
});
861+
862+
test('previous month button should instantly replace month view when animations are disabled', async ({ page }) => {
863+
test.info().annotations.push({
864+
type: 'issue',
865+
description: 'https://github.com/ionic-team/ionic-framework/issues/30484',
866+
});
867+
868+
await page.addInitScript(() => {
869+
(window as any).__scrollToCalls = [];
870+
const original = Element.prototype.scrollTo;
871+
Element.prototype.scrollTo = function (this: Element, ...args: any[]) {
872+
if (this.classList?.contains('calendar-body')) {
873+
(window as any).__scrollToCalls.push(args[0]);
874+
}
875+
return (original as any).apply(this, args);
876+
};
877+
});
878+
879+
await page.setContent(
880+
`
881+
<script>window.Ionic = {config: {animated: false}};</script>
882+
<ion-datetime value="2026-06-19T16:08:25.697Z"></ion-datetime>
883+
`,
884+
config
885+
);
886+
await page.locator('.datetime-ready').waitFor();
887+
888+
const prevMonthButton = page.locator('ion-datetime .calendar-next-prev ion-button').nth(0);
889+
await prevMonthButton.click();
890+
await page.waitForChanges();
891+
892+
const scrollCalls = await page.evaluate(() => (window as any).__scrollToCalls);
893+
894+
expect(scrollCalls.length).toBeGreaterThan(0);
895+
expect(scrollCalls[0].behavior).toBe('instant');
896+
});
897+
});
898+
});

0 commit comments

Comments
 (0)