Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(datetime): add animation to adjacent days selection #30298

Merged
merged 12 commits into from
Mar 28, 2025
Merged
3 changes: 2 additions & 1 deletion core/src/components/datetime/datetime.ios.scss
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@
* is selected should have ion-color for
* text color and be bolder.
*/
:host .calendar-day.calendar-day-active {
:host .calendar-day.calendar-day-active,
:host .calendar-day.calendar-day-adjacent-day.calendar-day-active {
color: current-color(base);

font-weight: 600;
Expand Down
3 changes: 2 additions & 1 deletion core/src/components/datetime/datetime.md.scss
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@
* is selected should have ion-color for
* text color and be bolder.
*/
:host .calendar-day.calendar-day-active {
:host .calendar-day.calendar-day-active,
:host .calendar-day.calendar-day-adjacent-day.calendar-day-active {
color: current-color(contrast);
}

Expand Down
43 changes: 16 additions & 27 deletions core/src/components/datetime/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2383,35 +2383,24 @@ export class Datetime implements ComponentInterface {
if (isAdjacentDay) {
// The user selected a day outside the current month. Ignore this button, as the month will be re-rendered.
this.el.blur();
}

this.setWorkingParts({
...this.workingParts,
month: _month,
day,
year: _year,
isAdjacentDay,
});

// multiple only needs date info, so we can wipe out other fields like time
if (multiple) {
this.setActiveParts(
{
month: _month,
day,
year: _year,
isAdjacentDay,
},
isActive
);
this.activeParts = { ...activePart, ...referenceParts };
this.animateToDate(referenceParts);
this.confirm();
} else {
this.setActiveParts({
...activePart,
month: _month,
day,
year: _year,
isAdjacentDay,
this.setWorkingParts({
...this.workingParts,
...referenceParts,
});

// multiple only needs date info, so we can wipe out other fields like time
if (multiple) {
this.setActiveParts(referenceParts, isActive);
} else {
this.setActiveParts({
...activePart,
...referenceParts,
});
}
}
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,75 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
const datetime = page.locator('#display');
await expect(datetime).toHaveScreenshot(screenshot(`datetime-show-adjacent-days-display`));
});

test('should return the same date format on current month days and on adjacent days', async ({ page }) => {
await page.setContent(
`
<ion-datetime show-adjacent-days="true" value="2022-10-14T16:22:00.000Z" presentation="date"></ion-datetime>
`,
config
);

// Wait for the datetime to be ready.
await page.locator('.datetime-ready').waitFor();

const ionChange = await page.spyOnEvent('ionChange');

const calendarMonthYear = page.locator('ion-datetime .calendar-month-year');

/**
* Make sure to exclude adjacent days from the query since
* the previous/next month is rendered hidden. This causes
* the query to possibly return different results: one for
* the current month and one from the hidden previous/next
* month.
*/
const october20Button = page.locator(
'[data-month="10"][data-year="2022"][data-day="20"]:not(.calendar-day-adjacent-day)'
);

await october20Button.click();

await ionChange.next();
await expect(ionChange).toHaveReceivedEventDetail({
value: '2022-10-20T16:22:00',
});

const november1Button = page.locator(
'.calendar-day-adjacent-day[data-month="11"][data-year="2022"][data-day="1"]'
);

await november1Button.click();
// Wait for the datetime to change the month since an adjacent day
// was clicked.
await page.waitForChanges();

// Wait for the title to update to the new month since it changes
// after the month animation finishes.
await expect(calendarMonthYear).toHaveText('November 2022');

await ionChange.next();
await expect(ionChange).toHaveReceivedEventDetail({
value: '2022-11-01T16:22:00',
});

/**
* Make sure to exclude adjacent days from the query since
* the previous/next month is rendered hidden. This causes
* the query to possibly return different results: one for
* the current month and one from the hidden previous/next
* month.
*/
const november22Button = page.locator(
'[data-month="11"][data-year="2022"][data-day="22"]:not(.calendar-day-adjacent-day)'
);

await november22Button.click();

await ionChange.next();
await expect(ionChange).toHaveReceivedEventDetail({
value: '2022-11-22T16:22:00',
});
});
});
});
13 changes: 13 additions & 0 deletions core/src/components/datetime/test/show-adjacent-days/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ <h2>Change firstDayOfWeek</h2>
<br /><br />
<ion-datetime show-adjacent-days="true" id="display" value="2022-02-22T16:30:00"></ion-datetime>
</div>

<ion-datetime
id="default2"
show-adjacent-days="true"
locale="en-US"
value="2022-10-14T16:22:00.000Z"
presentation="date"
></ion-datetime>
</ion-content>
</ion-app>

Expand Down Expand Up @@ -305,6 +313,11 @@ <h2>Change firstDayOfWeek</h2>
};

initCalendarMonthChangeObserver();

const datetimeDefault = document.querySelector('#default2');
datetimeDefault.addEventListener('ionChange', (ev) => {
console.log(ev.target.value);
});
</script>
</body>
</html>
Loading