Skip to content

Commit

Permalink
fix(datetime): empty string is treated as no value (#26131)
Browse files Browse the repository at this point in the history
resolves #26116
  • Loading branch information
liamdebeasi committed Oct 17, 2022
1 parent 0548fe8 commit 51ab5f6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class ValueAccessor implements ControlValueAccessor, AfterViewInit, OnDes

writeValue(value: any): void {
/**
* TODO for Ionic 6:
* TODO FW-2646
* Change `value == null ? '' : value;`
* to `value`. This was a fix for IE9, but IE9
* is no longer supported; however, this change
Expand Down
3 changes: 2 additions & 1 deletion core/src/components/datetime-button/datetime-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ export class DatetimeButton implements ComponentInterface {
* to keep checking if the datetime value is `string` or `string[]`.
*/
private getParsedDateValues = (value?: string[] | string | null): string[] => {
if (value === undefined || value === null) {
// TODO FW-2646 Remove value === ''
if (value === '' || value === undefined || value === null) {
return [];
}

Expand Down
7 changes: 5 additions & 2 deletions core/src/components/datetime/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1154,8 +1154,11 @@ export class Datetime implements ComponentInterface {
}

private processValue = (value?: string | string[] | null) => {
const hasValue = value !== null && value !== undefined;
let valueToProcess = parseDate(value ?? getToday());
/**
* TODO FW-2646 remove value !== ''
*/
const hasValue = value !== '' && value !== null && value !== undefined;
let valueToProcess = parseDate(hasValue ? value : getToday());

const { minParts, maxParts, multiple } = this;
if (!multiple && Array.isArray(value)) {
Expand Down
14 changes: 14 additions & 0 deletions core/src/components/datetime/test/values/datetime.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,17 @@ test.describe('datetime: values', () => {
await expect(items).toHaveText(['01', '02', '03']);
});
});

test('setting value to empty string should treat it as having no date', async ({ page, skip }) => {
skip.rtl();
skip.mode('ios');
await page.setContent(`
<ion-datetime value="" locale="en-US"></ion-datetime>
`);

await page.waitForSelector('.datetime-ready');

// Should render current month with today outlined.
const calendarDayToday = page.locator('ion-datetime .calendar-day-today');
await expect(calendarDayToday).toBeVisible();
});

0 comments on commit 51ab5f6

Please sign in to comment.