Skip to content
Open
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
1 change: 1 addition & 0 deletions BREAKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ This section details the desktop browser and mobile platform versions that are s
<h4 id="version-10x-datetime">Datetime</h4>

- The `ion-buttons` component has been removed from the internal implementation of `ion-datetime` and is no longer required when passing custom buttons to the `slot="buttons"`. When providing custom buttons, use a `div` element instead of `ion-buttons`. While existing code using `ion-buttons` may continue to work visually, future updates to the `ion-buttons` component may cause any styles you rely on to break.
- Confirming a selection without an initial `value` no longer includes the current time for presentations that do not render a time picker (`date`, `month`, `year`, and `month-year`). These presentations emitted a full timestamp (e.g. `2026-09-01T16:19:00`) where the time was the device clock when the component loaded. They now emit date-only values (e.g. `2026-09-01`), matching the behavior when a date-only `value` is passed. Applications that relied on the time portion should use the `date-time` or `time-date` presentations.

<h4 id="version-10x-grid">Grid</h4>

Expand Down
15 changes: 14 additions & 1 deletion core/src/components/datetime/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
getPreviousWeek,
getPreviousYear,
getStartOfWeek,
removeTimeParts,
validateParts,
} from './utils/manipulation';
import {
Expand Down Expand Up @@ -1846,7 +1847,7 @@ export class Datetime implements ComponentInterface {
this.processMinParts();
this.processMaxParts();

this.defaultParts = getClosestValidDate({
const defaultParts = getClosestValidDate({
refParts: todayParts,
monthValues,
dayValues,
Expand All @@ -1857,6 +1858,18 @@ export class Datetime implements ComponentInterface {
maxParts: this.maxParts,
});

/**
* Presentations without a time picker should not carry
* the current time into the default parts. Otherwise,
* confirming a selection without an initial value emits
* a full timestamp (e.g. `2026-09-01T16:19:00` for
* `presentation="date"`) instead of the date-only string
* the presentation describes.
*/
this.defaultParts = ['time', 'date-time', 'time-date'].includes(this.presentation)
? defaultParts
: removeTimeParts(defaultParts);

this.processValue(this.value);

this.emitStyle();
Expand Down
45 changes: 45 additions & 0 deletions core/src/components/datetime/test/basic/datetime.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,51 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
await datetime.evaluate((el: HTMLIonDatetimeElement) => (el.value = '2022-01-01'));
await expect(ionChange).not.toHaveReceivedEvent();
});

test('should emit a date-only value when confirming a selection without an initial value', async ({ page }) => {
await page.setContent(
`
<ion-datetime presentation="date"></ion-datetime>
`,
config
);

await page.locator('.datetime-ready').waitFor();

const ionChange = await page.spyOnEvent('ionChange');
const targetDay = page.locator('.calendar-day[data-day="10"]:not(.calendar-day-adjacent-day)').first();

const expectedValue = await targetDay.evaluate(
(el: HTMLElement) =>
`${el.dataset.year}-${String(el.dataset.month).padStart(2, '0')}-${String(el.dataset.day).padStart(2, '0')}`
);

await targetDay.click();

const ev = await ionChange.next();
expect(ev.detail.value).toBe(expectedValue);
});

test('should emit a value with time when confirming a selection without an initial value on date-time', async ({
page,
}) => {
await page.setContent(
`
<ion-datetime presentation="date-time"></ion-datetime>
`,
config
);

await page.locator('.datetime-ready').waitFor();

const ionChange = await page.spyOnEvent('ionChange');
const targetDay = page.locator('.calendar-day[data-day="10"]:not(.calendar-day-adjacent-day)').first();

await targetDay.click();

const ev = await ionChange.next();
expect(ev.detail.value).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:00$/);
});
});
});

Expand Down
16 changes: 16 additions & 0 deletions core/src/components/datetime/utils/manipulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ export function convertDataToISO(data: DatetimeParts | DatetimeParts[]): string
return rtn;
}

/**
* Removes the time fields (hour, minute, ampm) from
* the provided parts so only the date fields remain.
* Used by presentations that do not render a time
* picker, where carrying the current time into the
* default parts would leak a full timestamp into the
* emitted value instead of a date-only string.
*/
export const removeTimeParts = (parts: DatetimeParts): DatetimeParts => {
const dateParts = { ...parts };
delete dateParts.hour;
delete dateParts.minute;
delete dateParts.ampm;
return dateParts;
};

/**
* Converts an 12 hour value to 24 hours.
*/
Expand Down