fix(datetime): do not animate to new value when multiple values set

This commit is contained in:
Liam DeBeasi
2023-11-29 16:28:19 -05:00
parent 9fd65cbeeb
commit 12ba20917d

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,
});
}
}
};