Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions core/src/components/datetime/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { isRTL } from '@utils/rtl';
import { createColorClasses } from '@utils/theme';
import { caretDownSharp, caretUpSharp, chevronBack, chevronDown, chevronForward } from 'ionicons/icons';

import { config } from '../../global/config';
import { getIonMode } from '../../global/ionic-global';
import type { Color, Mode, StyleEventDetail } from '../../interface';

Expand Down Expand Up @@ -1555,10 +1556,11 @@ export class Datetime implements ComponentInterface {

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

const scrollMode = config.getBoolean('animated', true) ? 'smooth' : 'instant';
calendarBodyRef.scrollTo({
top: 0,
left: left * (isRTL(this.el) ? -1 : 1),
behavior: 'smooth',
behavior: scrollMode,
});
};

Expand All @@ -1575,10 +1577,11 @@ export class Datetime implements ComponentInterface {

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

const scrollMode = config.getBoolean('animated', true) ? 'smooth' : 'instant';
calendarBodyRef.scrollTo({
top: 0,
left: left * (isRTL(this.el) ? 1 : -1),
behavior: 'smooth',
behavior: scrollMode,
});
};

Expand Down
80 changes: 80 additions & 0 deletions core/src/components/datetime/test/basic/datetime.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,3 +816,83 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
});
});
});

/**
* This behavior does not differ across
* modes/directions.
*/
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
test.describe(title('datetime: animated'), () => {
test('next month button should instantly replace month view when animations are disabled', async ({ page }) => {
test.info().annotations.push({
type: 'issue',
description: 'https://github.com/ionic-team/ionic-framework/issues/30484',
});

await page.addInitScript(() => {
(window as any).__scrollToCalls = [];
const original = Element.prototype.scrollTo;
Element.prototype.scrollTo = function (this: Element, ...args: any[]) {
if (this.classList?.contains('calendar-body')) {
(window as any).__scrollToCalls.push(args[0]);
}
return (original as any).apply(this, args);
};
});

await page.setContent(
`
<script>window.Ionic = {config: {animated: false}};</script>
<ion-datetime value="2026-06-19T16:08:25.697Z"></ion-datetime>
`,
config
);
await page.locator('.datetime-ready').waitFor();

const nextMonthButton = page.locator('ion-datetime .calendar-next-prev ion-button').nth(1);
await nextMonthButton.click();
await page.waitForChanges();

const scrollCalls = await page.evaluate(() => (window as any).__scrollToCalls);

expect(scrollCalls.length).toBeGreaterThan(0);
expect(scrollCalls[0].behavior).toBe('instant');
});

test('previous month button should instantly replace month view when animations are disabled', async ({ page }) => {
test.info().annotations.push({
type: 'issue',
description: 'https://github.com/ionic-team/ionic-framework/issues/30484',
});

await page.addInitScript(() => {
(window as any).__scrollToCalls = [];
const original = Element.prototype.scrollTo;
Element.prototype.scrollTo = function (this: Element, ...args: any[]) {
if (this.classList?.contains('calendar-body')) {
(window as any).__scrollToCalls.push(args[0]);
}
return (original as any).apply(this, args);
};
});

await page.setContent(
`
<script>window.Ionic = {config: {animated: false}};</script>
<ion-datetime value="2026-06-19T16:08:25.697Z"></ion-datetime>
`,
config
);
await page.locator('.datetime-ready').waitFor();

const prevMonthButton = page.locator('ion-datetime .calendar-next-prev ion-button').nth(0);
await prevMonthButton.click();
await page.waitForChanges();

const scrollCalls = await page.evaluate(() => (window as any).__scrollToCalls);

expect(scrollCalls.length).toBeGreaterThan(0);
expect(scrollCalls[0].behavior).toBe('instant');
});
});
});
Loading