mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-09 16:16:41 +08:00
fix(datetime): update active day styling when day is selected (#24454)
Resolves #24414, #24451
This commit is contained in:
@ -273,6 +273,11 @@ export class Datetime implements ComponentInterface {
|
|||||||
this.parsedMinuteValues = convertToArrayOfNumbers(this.minuteValues);
|
this.parsedMinuteValues = convertToArrayOfNumbers(this.minuteValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Watch('activeParts')
|
||||||
|
protected activePartsChanged() {
|
||||||
|
this.activePartsClone = this.activeParts;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The locale to use for `ion-datetime`. This
|
* The locale to use for `ion-datetime`. This
|
||||||
* impacts month and day name formatting.
|
* impacts month and day name formatting.
|
||||||
@ -802,14 +807,14 @@ export class Datetime implements ComponentInterface {
|
|||||||
startIO = new IntersectionObserver(ev => ioCallback('start', ev), {
|
startIO = new IntersectionObserver(ev => ioCallback('start', ev), {
|
||||||
threshold: mode === 'ios' ? [0.7, 1] : 1,
|
threshold: mode === 'ios' ? [0.7, 1] : 1,
|
||||||
root: calendarBodyRef
|
root: calendarBodyRef
|
||||||
});
|
});
|
||||||
startIO.observe(startMonth);
|
startIO.observe(startMonth);
|
||||||
|
|
||||||
this.destroyCalendarIO = () => {
|
this.destroyCalendarIO = () => {
|
||||||
endIO?.disconnect();
|
endIO?.disconnect();
|
||||||
startIO?.disconnect();
|
startIO?.disconnect();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
@ -944,7 +949,7 @@ export class Datetime implements ComponentInterface {
|
|||||||
ampm: hour >= 12 ? 'pm' : 'am'
|
ampm: hour >= 12 ? 'pm' : 'am'
|
||||||
}
|
}
|
||||||
|
|
||||||
this.activePartsClone = this.activeParts = {
|
this.activeParts = {
|
||||||
month,
|
month,
|
||||||
day,
|
day,
|
||||||
year,
|
year,
|
||||||
@ -1206,7 +1211,7 @@ export class Datetime implements ComponentInterface {
|
|||||||
month,
|
month,
|
||||||
day,
|
day,
|
||||||
year
|
year
|
||||||
})
|
});
|
||||||
}}
|
}}
|
||||||
>{day}</button>
|
>{day}</button>
|
||||||
)
|
)
|
||||||
@ -1249,7 +1254,7 @@ export class Datetime implements ComponentInterface {
|
|||||||
minutesItems: PickerColumnItem[],
|
minutesItems: PickerColumnItem[],
|
||||||
ampmItems: PickerColumnItem[],
|
ampmItems: PickerColumnItem[],
|
||||||
use24Hour: boolean
|
use24Hour: boolean
|
||||||
) {
|
) {
|
||||||
const { color, activePartsClone, workingParts } = this;
|
const { color, activePartsClone, workingParts } = this;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -1290,7 +1295,7 @@ export class Datetime implements ComponentInterface {
|
|||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
}}
|
}}
|
||||||
></ion-picker-column-internal>
|
></ion-picker-column-internal>
|
||||||
{ !use24Hour && <ion-picker-column-internal
|
{!use24Hour && <ion-picker-column-internal
|
||||||
color={color}
|
color={color}
|
||||||
value={activePartsClone.ampm}
|
value={activePartsClone.ampm}
|
||||||
items={ampmItems}
|
items={ampmItems}
|
||||||
@ -1311,7 +1316,7 @@ export class Datetime implements ComponentInterface {
|
|||||||
|
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
}}
|
}}
|
||||||
></ion-picker-column-internal> }
|
></ion-picker-column-internal>}
|
||||||
</ion-picker-internal>
|
</ion-picker-internal>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -1321,7 +1326,7 @@ export class Datetime implements ComponentInterface {
|
|||||||
minutesItems: PickerColumnItem[],
|
minutesItems: PickerColumnItem[],
|
||||||
ampmItems: PickerColumnItem[],
|
ampmItems: PickerColumnItem[],
|
||||||
use24Hour: boolean
|
use24Hour: boolean
|
||||||
) {
|
) {
|
||||||
return [
|
return [
|
||||||
<div class="time-header">
|
<div class="time-header">
|
||||||
{this.renderTimeLabel()}
|
{this.renderTimeLabel()}
|
||||||
@ -1411,7 +1416,7 @@ export class Datetime implements ComponentInterface {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="datetime-time">
|
<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>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user