Compare commits

...

3 Commits

Author SHA1 Message Date
Liam DeBeasi
9f9a25614e add annotation 2023-11-29 16:42:03 -05:00
Liam DeBeasi
12ba20917d fix(datetime): do not animate to new value when multiple values set 2023-11-29 16:28:19 -05:00
Liam DeBeasi
9fd65cbeeb test(datetime): verify the datetime scrolls to value when 1 value set with multiple 2023-11-29 16:27:34 -05:00
2 changed files with 54 additions and 15 deletions

View File

@@ -1272,21 +1272,31 @@ export class Datetime implements ComponentInterface {
(month !== undefined && month !== workingParts.month) || (year !== undefined && year !== workingParts.year);
const bodyIsVisible = el.classList.contains('datetime-ready');
const { isGridStyle, showMonthAndYear } = this;
if (isGridStyle && didChangeMonth && bodyIsVisible && !showMonthAndYear) {
this.animateToDate(targetValue);
} else {
/**
* We only need to do this if we didn't just animate to a new month,
* since that calls prevMonth/nextMonth which calls setWorkingParts for us.
*/
this.setWorkingParts({
month,
day,
year,
hour,
minute,
ampm,
});
const hasSingleDateSelected = Array.isArray(valueToProcess) ? valueToProcess.length === 1 : true;
/**
* If there is more than one date selected
* then we should neither animate to the date
* nor update the working parts because we do
* not know which date the user wants to view.
*/
if (hasSingleDateSelected) {
if (isGridStyle && didChangeMonth && bodyIsVisible && !showMonthAndYear) {
this.animateToDate(targetValue);
} else {
/**
* We only need to do this if we didn't just animate to a new month,
* since that calls prevMonth/nextMonth which calls setWorkingParts for us.
*/
this.setWorkingParts({
month,
day,
year,
hour,
minute,
ampm,
});
}
}
};

View File

@@ -62,5 +62,34 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
const calendarHeader = datetime.locator('.calendar-month-year');
await expect(calendarHeader).toHaveText(/May 2021/);
});
test('should scroll to new month when value is initially set and then updated with multiple selection', async ({
page,
}) => {
test.info().annotations.push({
type: 'issue',
description: 'https://github.com/ionic-team/ionic-framework/issues/28602',
});
await page.setContent(
`
<ion-datetime multiple="true" presentation="date"></ion-datetime>
<script>
const datetime = document.querySelector('ion-datetime');
datetime.value = ['2021-04-25'];
</script>
`,
config
);
await page.waitForSelector('.datetime-ready');
const datetime = page.locator('ion-datetime');
await datetime.evaluate((el: HTMLIonDatetimeElement) => (el.value = '2021-05-25T12:40:00.000Z'));
await page.waitForChanges();
const calendarHeader = datetime.locator('.calendar-month-year');
await expect(calendarHeader).toHaveText(/May 2021/);
});
});
});