mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 04:14:21 +08:00
fix(datetime): don't update value on confirm call if no date was selected (#25338)
This commit is contained in:
@ -441,6 +441,13 @@ export class Datetime implements ComponentInterface {
|
||||
*/
|
||||
@Method()
|
||||
async confirm(closeOverlay = false) {
|
||||
/**
|
||||
* If highlightActiveParts is false, this means the datetime was inited
|
||||
* without a value, and the user hasn't selected one yet. We shouldn't
|
||||
* update the value in this case, since otherwise it would be mysteriously
|
||||
* set to today.
|
||||
*/
|
||||
if (this.highlightActiveParts) {
|
||||
/**
|
||||
* Prevent convertDataToISO from doing any
|
||||
* kind of transformation based on timezone
|
||||
@ -454,6 +461,7 @@ export class Datetime implements ComponentInterface {
|
||||
this.activeParts.tzOffset = date.getTimezoneOffset() * -1;
|
||||
|
||||
this.value = convertDataToISO(this.activeParts);
|
||||
}
|
||||
|
||||
if (closeOverlay) {
|
||||
this.closeParentOverlay();
|
||||
|
@ -29,3 +29,20 @@ test.describe('datetime: selecting a day', () => {
|
||||
await testHighlight(page, 'custom-datetime');
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('datetime: confirm date', () => {
|
||||
test('should not update value if Done was clicked without selecting a day first', async ({ page }) => {
|
||||
await page.goto('/src/components/datetime/test/basic');
|
||||
|
||||
const datetime = page.locator('#custom-datetime');
|
||||
|
||||
const value = await datetime.evaluate((el: HTMLIonDatetimeElement) => el.value);
|
||||
expect(value).toBeUndefined();
|
||||
|
||||
await datetime.evaluate(async (el: HTMLIonDatetimeElement) => {
|
||||
await el.confirm();
|
||||
});
|
||||
const valueAgain = await datetime.evaluate((el: HTMLIonDatetimeElement) => el.value);
|
||||
expect(valueAgain).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user