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

fix(datetime): update active day styling when day is selected #24454

Merged
merged 3 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions core/src/components/datetime/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -944,7 +949,7 @@ export class Datetime implements ComponentInterface {
ampm: hour >= 12 ? 'pm' : 'am'
}

this.activePartsClone = this.activeParts = {
this.activeParts = {
month,
day,
year,
Expand Down Expand Up @@ -1206,7 +1211,7 @@ export class Datetime implements ComponentInterface {
month,
day,
year
})
});
}}
>{day}</button>
)
Expand Down Expand Up @@ -1249,7 +1254,7 @@ export class Datetime implements ComponentInterface {
minutesItems: PickerColumnItem[],
ampmItems: PickerColumnItem[],
use24Hour: boolean
) {
) {
const { color, activePartsClone, workingParts } = this;

return (
Expand Down Expand Up @@ -1290,7 +1295,7 @@ export class Datetime implements ComponentInterface {
ev.stopPropagation();
}}
></ion-picker-column-internal>
{ !use24Hour && <ion-picker-column-internal
{!use24Hour && <ion-picker-column-internal
color={color}
value={activePartsClone.ampm}
items={ampmItems}
Expand All @@ -1311,7 +1316,7 @@ export class Datetime implements ComponentInterface {

ev.stopPropagation();
}}
></ion-picker-column-internal> }
></ion-picker-column-internal>}
</ion-picker-internal>
)
}
Expand All @@ -1321,7 +1326,7 @@ export class Datetime implements ComponentInterface {
minutesItems: PickerColumnItem[],
ampmItems: PickerColumnItem[],
use24Hour: boolean
) {
) {
return [
<div class="time-header">
{this.renderTimeLabel()}
Expand Down Expand Up @@ -1411,7 +1416,7 @@ export class Datetime implements ComponentInterface {

return (
<div class="datetime-time">
{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)}
</div>
)
}
Expand Down
22 changes: 22 additions & 0 deletions core/src/components/datetime/test/basic/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,25 @@ describe('Footer', () => {
});


describe('datetime: selecting a day', () => {

it('should update the active day', async () => {
const page = await newE2EPage({
html: `
<ion-datetime show-default-buttons="true" value="2021-12-25T12:40:00.000Z"></ion-datetime>
`
});

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