Skip to content

Commit bf46a3d

Browse files
authored
fix(datetime): don't setActiveParts from month/year wheels when multiple=true (#31248)
Issue number: resolves #29673 --------- ## What is the current behavior? Using the month/year selection wheels on an `ion-datetime` with `multiple=true` changes the selection in an unintuitive manner and changing the value of one of the wheels often reverts the value of the other wheel. ## What is the new behavior? - The month and year wheels in an `ion-datetime` no longer change the selection when `multiple=true` - The behavior of a single-select `ion-datetime` is unchanged. - The fix has only been applied to `renderMonthPickerColumn` and `renderYearPickerColumn`, as [per the docs](https://ionicframework.com/docs/api/datetime#multiple-date-selection), the `multiple` property is only supported on `presentation=date preferWheel=false`, which only shows those two wheels. - Four new datetime e2e tests have been added to test these changes ## Does this introduce a breaking change? - [ ] Yes - [x] No
1 parent 0c76135 commit bf46a3d

2 files changed

Lines changed: 135 additions & 8 deletions

File tree

core/src/components/datetime/datetime.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,10 +1966,13 @@ export class Datetime implements ComponentInterface {
19661966
month: ev.detail.value,
19671967
});
19681968

1969-
this.setActiveParts({
1970-
...activePart,
1971-
month: ev.detail.value,
1972-
});
1969+
// Month wheel is navigation-only in multi-select mode as a fix for https://github.com/ionic-team/ionic-framework/issues/29673
1970+
if (!this.multiple) {
1971+
this.setActiveParts({
1972+
...activePart,
1973+
month: ev.detail.value,
1974+
});
1975+
}
19731976

19741977
ev.stopPropagation();
19751978
}}
@@ -2010,10 +2013,13 @@ export class Datetime implements ComponentInterface {
20102013
year: ev.detail.value,
20112014
});
20122015

2013-
this.setActiveParts({
2014-
...activePart,
2015-
year: ev.detail.value,
2016-
});
2016+
// Year wheel is navigation-only in multi-select mode as a fix for https://github.com/ionic-team/ionic-framework/issues/29673
2017+
if (!this.multiple) {
2018+
this.setActiveParts({
2019+
...activePart,
2020+
year: ev.detail.value,
2021+
});
2022+
}
20172023

20182024
ev.stopPropagation();
20192025
}}

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

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,124 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
337337
});
338338
});
339339
});
340+
341+
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
342+
test.describe(
343+
title('datetime: interaction between month/year wheels and selected date(s) with different values of multiple'),
344+
() => {
345+
test('using month wheel should change selection when multiple=false', async ({ page }, testInfo) => {
346+
testInfo.annotations.push({
347+
type: 'issue',
348+
description: 'https://github.com/ionic-team/ionic-framework/issues/29673',
349+
});
350+
351+
await page.setContent(`<ion-datetime value="2026-06-26T10:36:00" locale="en-US"></ion-datetime>`, config);
352+
const datetime = page.locator('ion-datetime');
353+
354+
await page.waitForSelector('.datetime-ready');
355+
356+
const dropdownButton = page.locator('.calendar-month-year-toggle');
357+
await dropdownButton.click();
358+
await page.waitForChanges();
359+
360+
const monthOption = page.locator('.month-column ion-picker-column-option').nth(0);
361+
await monthOption.click();
362+
await page.waitForChanges();
363+
364+
await expect(datetime).toHaveJSProperty('value', '2026-01-26T10:36:00');
365+
});
366+
367+
test('using month wheel should not change selection when multiple=true', async ({ page }, testInfo) => {
368+
testInfo.annotations.push({
369+
type: 'issue',
370+
description: 'https://github.com/ionic-team/ionic-framework/issues/29673',
371+
});
372+
373+
await page.setContent(
374+
`
375+
<ion-datetime multiple locale="en-US"></ion-datetime>
376+
<script>
377+
const datetime = document.querySelector('ion-datetime');
378+
datetime.value = [ "2026-06-26T10:36:00", "2026-06-28T10:36:00", "2026-01-01T10:36:00" ];
379+
</script>
380+
`,
381+
config
382+
);
383+
const datetime = page.locator('ion-datetime');
384+
385+
await page.waitForSelector('.datetime-ready');
386+
387+
const dropdownButton = page.locator('.calendar-month-year-toggle');
388+
await dropdownButton.click();
389+
await page.waitForChanges();
390+
391+
const monthOption = page.locator('.month-column ion-picker-column-option').nth(0);
392+
await monthOption.click();
393+
await page.waitForChanges();
394+
395+
await expect(datetime).toHaveJSProperty('value', [
396+
'2026-06-26T10:36:00',
397+
'2026-06-28T10:36:00',
398+
'2026-01-01T10:36:00',
399+
]);
400+
});
401+
402+
test('using year wheel should change selection when multiple=false', async ({ page }, testInfo) => {
403+
testInfo.annotations.push({
404+
type: 'issue',
405+
description: 'https://github.com/ionic-team/ionic-framework/issues/29673',
406+
});
407+
408+
await page.setContent(`<ion-datetime value="2026-06-26T10:36:00" locale="en-US"></ion-datetime>`, config);
409+
const datetime = page.locator('ion-datetime');
410+
411+
await page.waitForSelector('.datetime-ready');
412+
413+
const dropdownButton = page.locator('.calendar-month-year-toggle');
414+
await dropdownButton.click();
415+
await page.waitForChanges();
416+
417+
const yearOption = page.locator('.year-column ion-picker-column-option').nth(0);
418+
await yearOption.click();
419+
await page.waitForChanges();
420+
421+
await expect(datetime).toHaveJSProperty('value', '1926-06-26T10:36:00');
422+
});
423+
424+
test('using year wheel should not change selection when multiple=true', async ({ page }, testInfo) => {
425+
testInfo.annotations.push({
426+
type: 'issue',
427+
description: 'https://github.com/ionic-team/ionic-framework/issues/29673',
428+
});
429+
430+
await page.setContent(
431+
`
432+
<ion-datetime multiple locale="en-US"></ion-datetime>
433+
<script>
434+
const datetime = document.querySelector('ion-datetime');
435+
datetime.value = [ "2026-06-26T10:36:00", "2026-06-28T10:36:00", "2026-01-01T10:36:00" ];
436+
</script>
437+
`,
438+
config
439+
);
440+
const datetime = page.locator('ion-datetime');
441+
442+
await page.waitForSelector('.datetime-ready');
443+
444+
const dropdownButton = page.locator('.calendar-month-year-toggle');
445+
await dropdownButton.click();
446+
await page.waitForChanges();
447+
448+
const yearOption = page.locator('.year-column ion-picker-column-option').nth(0);
449+
await yearOption.click();
450+
await page.waitForChanges();
451+
452+
await expect(datetime).toHaveJSProperty('value', [
453+
'2026-06-26T10:36:00',
454+
'2026-06-28T10:36:00',
455+
'2026-01-01T10:36:00',
456+
]);
457+
});
458+
}
459+
);
460+
});

0 commit comments

Comments
 (0)