diff --git a/core/src/components/datetime/datetime.ios.scss b/core/src/components/datetime/datetime.ios.scss index ce949f77a1..5da21dd60c 100644 --- a/core/src/components/datetime/datetime.ios.scss +++ b/core/src/components/datetime/datetime.ios.scss @@ -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; diff --git a/core/src/components/datetime/datetime.md.scss b/core/src/components/datetime/datetime.md.scss index b008951db1..fe592b9e94 100644 --- a/core/src/components/datetime/datetime.md.scss +++ b/core/src/components/datetime/datetime.md.scss @@ -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); } diff --git a/core/src/components/datetime/datetime.tsx b/core/src/components/datetime/datetime.tsx index 0c158ba706..d06e3ce116 100644 --- a/core/src/components/datetime/datetime.tsx +++ b/core/src/components/datetime/datetime.tsx @@ -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, + }); + } } }} > diff --git a/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts b/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts index ac45fd4202..05a50d1521 100644 --- a/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts +++ b/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts @@ -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( + ` + + `, + 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', + }); + }); }); }); diff --git a/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-ios-ltr-Mobile-Chrome-linux.png b/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-ios-ltr-Mobile-Chrome-linux.png index 2352f2c948..6005631303 100644 Binary files a/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-ios-ltr-Mobile-Chrome-linux.png and b/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-ios-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-ios-ltr-Mobile-Firefox-linux.png b/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-ios-ltr-Mobile-Firefox-linux.png index 8b828935e1..d67765af39 100644 Binary files a/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-ios-ltr-Mobile-Firefox-linux.png and b/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-ios-ltr-Mobile-Firefox-linux.png differ diff --git a/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-md-ltr-Mobile-Chrome-linux.png b/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-md-ltr-Mobile-Chrome-linux.png index 0f73846e6d..ba83afc568 100644 Binary files a/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-md-ltr-Mobile-Chrome-linux.png and b/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-md-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-md-ltr-Mobile-Firefox-linux.png b/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-md-ltr-Mobile-Firefox-linux.png index 194e6b8cd9..9de6935f65 100644 Binary files a/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-md-ltr-Mobile-Firefox-linux.png and b/core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-md-ltr-Mobile-Firefox-linux.png differ diff --git a/core/src/components/datetime/test/show-adjacent-days/index.html b/core/src/components/datetime/test/show-adjacent-days/index.html index 167da8663b..55d6dc2bfc 100644 --- a/core/src/components/datetime/test/show-adjacent-days/index.html +++ b/core/src/components/datetime/test/show-adjacent-days/index.html @@ -161,22 +161,35 @@ FirstDayOfWeek: 1 + +
+

DateTime format with IonChange Event (console)

+ +
-
- - - - -

- +
+
+ + + + +

+ +
@@ -305,6 +318,11 @@ }; initCalendarMonthChangeObserver(); + + const datetimeDefault = document.querySelector('#default2'); + datetimeDefault.addEventListener('ionChange', (ev) => { + console.log(ev.target.value); + });