diff --git a/core/src/components/datetime/datetime.tsx b/core/src/components/datetime/datetime.tsx index 2ae9db4565..4e9d22a500 100644 --- a/core/src/components/datetime/datetime.tsx +++ b/core/src/components/datetime/datetime.tsx @@ -273,6 +273,11 @@ export class Datetime implements ComponentInterface { this.parsedMinuteValues = convertToArrayOfNumbers(this.minuteValues); } + @Watch('activeParts') + protected activePartsChanged() { + this.activePartsClone = this.activeParts; + } + /** * The locale to use for `ion-datetime`. This * impacts month and day name formatting. @@ -802,14 +807,14 @@ export class Datetime implements ComponentInterface { startIO = new IntersectionObserver(ev => ioCallback('start', ev), { threshold: mode === 'ios' ? [0.7, 1] : 1, root: calendarBodyRef - }); + }); startIO.observe(startMonth); this.destroyCalendarIO = () => { endIO?.disconnect(); startIO?.disconnect(); } - }); + }); } connectedCallback() { @@ -944,7 +949,7 @@ export class Datetime implements ComponentInterface { ampm: hour >= 12 ? 'pm' : 'am' } - this.activePartsClone = this.activeParts = { + this.activeParts = { month, day, year, @@ -1206,7 +1211,7 @@ export class Datetime implements ComponentInterface { month, day, year - }) + }); }} >{day} ) @@ -1249,7 +1254,7 @@ export class Datetime implements ComponentInterface { minutesItems: PickerColumnItem[], ampmItems: PickerColumnItem[], use24Hour: boolean - ) { + ) { const { color, activePartsClone, workingParts } = this; return ( @@ -1290,7 +1295,7 @@ export class Datetime implements ComponentInterface { ev.stopPropagation(); }} > - { !use24Hour && } + >} ) } @@ -1321,7 +1326,7 @@ export class Datetime implements ComponentInterface { minutesItems: PickerColumnItem[], ampmItems: PickerColumnItem[], use24Hour: boolean - ) { + ) { return [
{this.renderTimeLabel()} @@ -1411,7 +1416,7 @@ export class Datetime implements ComponentInterface { return (
- {timeOnlyPresentation ? this.renderTimePicker(hoursItems, minutesItems, ampmItems, use24Hour) : this.renderTimeOverlay(hoursItems, minutesItems, ampmItems, use24Hour)} + {timeOnlyPresentation ? this.renderTimePicker(hoursItems, minutesItems, ampmItems, use24Hour) : this.renderTimeOverlay(hoursItems, minutesItems, ampmItems, use24Hour)}
) } diff --git a/core/src/components/datetime/test/basic/e2e.ts b/core/src/components/datetime/test/basic/e2e.ts index 33b586f357..89af77f041 100644 --- a/core/src/components/datetime/test/basic/e2e.ts +++ b/core/src/components/datetime/test/basic/e2e.ts @@ -79,3 +79,25 @@ describe('Footer', () => { }); +describe('datetime: selecting a day', () => { + + it('should update the active day', async () => { + const page = await newE2EPage({ + html: ` + + ` + }); + + const activeDay = await page.find('ion-datetime >>> .calendar-day-active'); + + expect(activeDay.innerText).toEqual('25'); + + const dayBtn = await page.find('ion-datetime >>> .calendar-day[data-day="13"][data-month="12"]'); + dayBtn.click(); + await page.waitForChanges(); + + const newActiveDay = await page.find('ion-datetime >>> .calendar-day-active'); + + expect(newActiveDay.innerText).toEqual('13'); + }); +});