Skip to content
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
10 changes: 10 additions & 0 deletions core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ ion-datetime,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "se
ion-datetime,prop,dayValues,number | number[] | string | undefined,undefined,false,false
ion-datetime,prop,disabled,boolean,false,false,false
ion-datetime,prop,doneText,string,'Done',false,false
ion-datetime,prop,endDateLabel,string,'End date',false,false
ion-datetime,prop,firstDayOfWeek,number,0,false,false
ion-datetime,prop,formatOptions,undefined | { date: DateTimeFormatOptions; time?: DateTimeFormatOptions | undefined; } | { date?: DateTimeFormatOptions | undefined; time: DateTimeFormatOptions; },undefined,false,false
ion-datetime,prop,highlightedDates,((dateIsoString: string) => DatetimeHighlightStyle | undefined) | DatetimeHighlight[] | undefined,undefined,false,false
Expand All @@ -858,12 +859,14 @@ ion-datetime,prop,name,string,this.inputId,false,false
ion-datetime,prop,preferWheel,boolean,false,false,false
ion-datetime,prop,presentation,"date" | "date-time" | "month" | "month-year" | "time" | "time-date" | "year",'date-time',false,false
ion-datetime,prop,readonly,boolean,false,false,false
ion-datetime,prop,selectionMode,"multiple" | "range" | undefined,undefined,false,false
ion-datetime,prop,showAdjacentDays,boolean,false,false,false
ion-datetime,prop,showClearButton,boolean,false,false,false
ion-datetime,prop,showDefaultButtons,boolean,false,false,false
ion-datetime,prop,showDefaultTimeLabel,boolean,true,false,false
ion-datetime,prop,showDefaultTitle,boolean,false,false,false
ion-datetime,prop,size,"cover" | "fixed",'fixed',false,false
ion-datetime,prop,startDateLabel,string,'Start date',false,false
ion-datetime,prop,theme,"ios" | "md" | "ionic",undefined,false,false
ion-datetime,prop,titleSelectedDatesFormatter,((selectedDates: string[]) => string) | undefined,undefined,false,false
ion-datetime,prop,value,null | string | string[] | undefined,undefined,false,false
Expand All @@ -882,6 +885,9 @@ ion-datetime,css-prop,--background-rgb,ios
ion-datetime,css-prop,--background-rgb,md
ion-datetime,css-prop,--focus-ring-color,ionic
ion-datetime,css-prop,--focus-ring-width,ionic
ion-datetime,css-prop,--range-background,ionic
ion-datetime,css-prop,--range-background,ios
ion-datetime,css-prop,--range-background,md
ion-datetime,css-prop,--title-color,ios
ion-datetime,css-prop,--title-color,md
ion-datetime,css-prop,--wheel-fade-background-rgb,ios
Expand All @@ -903,6 +909,10 @@ ion-datetime,part,month-year-button
ion-datetime,part,navigation-button
ion-datetime,part,next-button
ion-datetime,part,previous-button
ion-datetime,part,range-end
ion-datetime,part,range-selection
ion-datetime,part,range-start
ion-datetime,part,range-track
ion-datetime,part,time-button
ion-datetime,part,time-button active
ion-datetime,part,wheel
Expand Down
8 changes: 4 additions & 4 deletions core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"fs-extra": "^9.0.1",
"jest": "^29.7.0",
"jest-cli": "^29.7.0",
"outsystems-design-tokens": "^2.5.0",
"outsystems-design-tokens": "^2.6.0",
"playwright-core": "^1.64.0",
"prettier": "^2.8.8",
"rollup": "^2.26.4",
Expand Down
41 changes: 37 additions & 4 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,11 @@ export namespace Components {
* @default 'Done'
*/
"doneText": string;
/**
* The text shown in the datetime header when the end of the range is empty, also used by screen readers to announce the end date. Only applies when `selectionMode="range"`.
* @default 'End date'
*/
"endDateLabel": string;
/**
* The first day of the week to use for `ion-datetime`. The default value is `0` and represents Sunday.
* @default 0
Expand Down Expand Up @@ -1237,6 +1242,7 @@ export namespace Components {
"monthValues"?: number[] | number | string;
/**
* If `true`, multiple dates can be selected at once. Only applies to `presentation="date"` and `preferWheel="false"`.
* @deprecated Use `selectionMode="multiple"` instead.
* @default false
*/
"multiple": boolean;
Expand Down Expand Up @@ -1265,6 +1271,10 @@ export namespace Components {
* @param startDate A valid [ISO-8601 string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format) to reset the datetime state to.
*/
"reset": (startDate?: string) => Promise<void>;
/**
* Controls the date selection behavior. `'multiple'` enables selecting multiple individual dates. `'range'` enables selecting a start and end date range. When unset, single-date selection is used. Range selection only works with `presentation="date"` and `preferWheel="false"`.
*/
"selectionMode"?: 'multiple' | 'range';
/**
* If `true`, the datetime calendar displays a six-week (42-day) layout, including days from the previous and next months to fill the grid. These adjacent days are selectable unless disabled.
* @default false
Expand Down Expand Up @@ -1295,16 +1305,21 @@ export namespace Components {
* @default 'fixed'
*/
"size": 'cover' | 'fixed';
/**
* The text shown in the datetime header when the start of the range is empty, also used by screen readers to announce the start date. Only applies when `selectionMode="range"`.
* @default 'Start date'
*/
"startDateLabel": string;
/**
* The theme determines the visual appearance of the component.
*/
"theme"?: "ios" | "md" | "ionic";
/**
* A callback used to format the header text that shows how many dates are selected. Only used if there are 0 or more than 1 selected (i.e. unused for exactly 1). By default, the header text is set to "numberOfDates days". See https://ionicframework.com/docs/troubleshooting/runtime#accessing-this if you need to access `this` from within the callback.
* A callback used to format the header text that shows how many dates are selected. In multiple mode this is only used when there are 0 or more than 1 selected. In range mode it is always called with `[startDate]` or `[startDate, endDate]`. By default, the header text is set to "numberOfDates days". See https://ionicframework.com/docs/troubleshooting/runtime#accessing-this if you need to access `this` from within the callback.
*/
"titleSelectedDatesFormatter"?: TitleSelectedDatesFormatter;
/**
* The value of the datetime as a valid ISO 8601 datetime string. This should be an array of strings only when `multiple="true"`.
* The value of the datetime as a valid ISO 8601 datetime string. Should be an array of strings when using `multiple="true"` or `selectionMode="range"`. For range mode the array contains `[startDate, endDate]`, or `[startDate]` for a partial selection.
*/
"value"?: string | string[] | null;
/**
Expand Down Expand Up @@ -7029,6 +7044,11 @@ declare namespace LocalJSX {
* @default 'Done'
*/
"doneText"?: string;
/**
* The text shown in the datetime header when the end of the range is empty, also used by screen readers to announce the end date. Only applies when `selectionMode="range"`.
* @default 'End date'
*/
"endDateLabel"?: string;
/**
* The first day of the week to use for `ion-datetime`. The default value is `0` and represents Sunday.
* @default 0
Expand Down Expand Up @@ -7081,6 +7101,7 @@ declare namespace LocalJSX {
"monthValues"?: number[] | number | string;
/**
* If `true`, multiple dates can be selected at once. Only applies to `presentation="date"` and `preferWheel="false"`.
* @deprecated Use `selectionMode="multiple"` instead.
* @default false
*/
"multiple"?: boolean;
Expand Down Expand Up @@ -7132,6 +7153,10 @@ declare namespace LocalJSX {
* @default false
*/
"readonly"?: boolean;
/**
* Controls the date selection behavior. `'multiple'` enables selecting multiple individual dates. `'range'` enables selecting a start and end date range. When unset, single-date selection is used. Range selection only works with `presentation="date"` and `preferWheel="false"`.
*/
"selectionMode"?: 'multiple' | 'range';
/**
* If `true`, the datetime calendar displays a six-week (42-day) layout, including days from the previous and next months to fill the grid. These adjacent days are selectable unless disabled.
* @default false
Expand Down Expand Up @@ -7162,16 +7187,21 @@ declare namespace LocalJSX {
* @default 'fixed'
*/
"size"?: 'cover' | 'fixed';
/**
* The text shown in the datetime header when the start of the range is empty, also used by screen readers to announce the start date. Only applies when `selectionMode="range"`.
* @default 'Start date'
*/
"startDateLabel"?: string;
/**
* The theme determines the visual appearance of the component.
*/
"theme"?: "ios" | "md" | "ionic";
/**
* A callback used to format the header text that shows how many dates are selected. Only used if there are 0 or more than 1 selected (i.e. unused for exactly 1). By default, the header text is set to "numberOfDates days". See https://ionicframework.com/docs/troubleshooting/runtime#accessing-this if you need to access `this` from within the callback.
* A callback used to format the header text that shows how many dates are selected. In multiple mode this is only used when there are 0 or more than 1 selected. In range mode it is always called with `[startDate]` or `[startDate, endDate]`. By default, the header text is set to "numberOfDates days". See https://ionicframework.com/docs/troubleshooting/runtime#accessing-this if you need to access `this` from within the callback.
*/
"titleSelectedDatesFormatter"?: TitleSelectedDatesFormatter;
/**
* The value of the datetime as a valid ISO 8601 datetime string. This should be an array of strings only when `multiple="true"`.
* The value of the datetime as a valid ISO 8601 datetime string. Should be an array of strings when using `multiple="true"` or `selectionMode="range"`. For range mode the array contains `[startDate, endDate]`, or `[startDate]` for a partial selection.
*/
"value"?: string | string[] | null;
/**
Expand Down Expand Up @@ -10621,6 +10651,9 @@ declare namespace LocalJSX {
"locale": string;
"firstDayOfWeek": number;
"multiple": boolean;
"selectionMode": 'multiple' | 'range';
"startDateLabel": string;
"endDateLabel": string;
"value": string | string[] | null;
"showDefaultTitle": boolean;
"showDefaultButtons": boolean;
Expand Down
9 changes: 2 additions & 7 deletions core/src/components/accordion/accordion.ionic.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,5 @@

// Disabled Accordion
// --------------------------------------------------

:host(.accordion-disabled)::before {
@include globals.border-radius(inherit);
@include globals.disabled-state();

z-index: 2;
}
// The disabled colors are set in core.ionic.scss because the header
// and content are slotted (light DOM).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion core/src/components/action-sheet/action-sheet.ionic.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// --------------------------------------------------

:host {
--background: #{globals.$ion-bg-surface-default};
--background: #{globals.$ion-bg-surface-elevation-3};
--backdrop-opacity: 0.7;
--button-background: transparent;
--button-background-selected: #{globals.$ion-bg-primary-subtle-default};
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/alert/alert.ionic.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// --------------------------------------------------

:host {
--background: #{globals.$ion-bg-surface-default};
--background: #{globals.$ion-bg-surface-elevation-3};
--max-width: #{globals.$ion-scale-7400};
--backdrop-opacity: 0.7;

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 40 additions & 12 deletions core/src/components/datetime-button/datetime-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createColorClasses } from '@utils/theme';
import { getIonTheme } from '../../global/ionic-global';
import type { Color } from '../../interface';
import type { DatetimePresentation } from '../datetime/datetime-interface';
import { isAfter } from '../datetime/utils/comparison';
import { getLocalizedDateTime, getLocalizedTime } from '../datetime/utils/format';
import { getHourCycle } from '../datetime/utils/helpers';
import { parseDate } from '../datetime/utils/parse';
Expand Down Expand Up @@ -197,7 +198,16 @@ export class DatetimeButton implements ComponentInterface {
return;
}

const { value, locale, formatOptions, hourCycle, preferWheel, multiple, titleSelectedDatesFormatter } = datetimeEl;
const {
value,
locale,
formatOptions,
hourCycle,
preferWheel,
multiple,
selectionMode,
titleSelectedDatesFormatter,
} = datetimeEl;

const parsedValues = this.getParsedDateValues(value);

Expand All @@ -213,6 +223,9 @@ export class DatetimeButton implements ComponentInterface {
return;
}

const isRangeMode = selectionMode === 'range';
const isMultipleMode = selectionMode === 'multiple' || (selectionMode === undefined && multiple);

/**
* If developers incorrectly use multiple="true"
* with non "date" datetimes, then just select
Expand All @@ -222,17 +235,14 @@ export class DatetimeButton implements ComponentInterface {
*/
const firstParsedDatetime = parsedDatetimes[0];
const computedHourCycle = getHourCycle(locale, hourCycle);
const dateFormatOptions = formatOptions?.date ?? { month: 'short', day: 'numeric', year: 'numeric' };

this.dateText = this.timeText = undefined;

switch (datetimePresentation) {
case 'date-time':
case 'time-date':
const dateText = getLocalizedDateTime(
locale,
firstParsedDatetime,
formatOptions?.date ?? { month: 'short', day: 'numeric', year: 'numeric' }
);
const dateText = getLocalizedDateTime(locale, firstParsedDatetime, dateFormatOptions);
const timeText = getLocalizedTime(locale, firstParsedDatetime, computedHourCycle, formatOptions?.time);
if (preferWheel) {
this.dateText = `${dateText} ${timeText}`;
Expand All @@ -242,7 +252,29 @@ export class DatetimeButton implements ComponentInterface {
}
break;
case 'date':
if (multiple && parsedValues.length !== 1) {
if (isRangeMode && parsedValues.length >= 2) {
/**
* Use the first and last entries in date order, matching
* how ion-datetime reads a range value.
*/
let startIndex = 0;
let endIndex = parsedValues.length - 1;
if (isAfter(parsedDatetimes[startIndex], parsedDatetimes[endIndex])) {
[startIndex, endIndex] = [endIndex, startIndex];
}
const rangeValues = [parsedValues[startIndex], parsedValues[endIndex]];
const startDate = getLocalizedDateTime(locale, parsedDatetimes[startIndex], dateFormatOptions);
const endDate = getLocalizedDateTime(locale, parsedDatetimes[endIndex], dateFormatOptions);
let rangeText = `${startDate} - ${endDate}`;
if (titleSelectedDatesFormatter !== undefined) {
try {
rangeText = titleSelectedDatesFormatter(rangeValues);
} catch (e) {
printIonError('[ion-datetime-button] - Exception in provided `titleSelectedDatesFormatter`:', e);
}
}
this.dateText = rangeText;
} else if (isMultipleMode && parsedValues.length !== 1) {
let headerText = `${parsedValues.length} days`; // default/fallback for multiple selection
if (titleSelectedDatesFormatter !== undefined) {
try {
Expand All @@ -253,11 +285,7 @@ export class DatetimeButton implements ComponentInterface {
}
this.dateText = headerText;
} else {
this.dateText = getLocalizedDateTime(
locale,
firstParsedDatetime,
formatOptions?.date ?? { month: 'short', day: 'numeric', year: 'numeric' }
);
this.dateText = getLocalizedDateTime(locale, firstParsedDatetime, dateFormatOptions);
}
break;
case 'time':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,26 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
});
});

test.describe(title('datetime-button: range mode'), () => {
test('should normalize a reversed range value to chronological order', async ({ page }) => {
await page.setContent(
`
<ion-datetime-button locale="en-US" datetime="datetime"></ion-datetime-button>
<ion-datetime id="datetime" presentation="date" selection-mode="range"></ion-datetime>
<script>
const datetime = document.querySelector('ion-datetime');
datetime.value = ['2023-10-31', '2023-10-23'];
</script>
`,
config
);
await page.locator('.datetime-ready').waitFor();

const dateButton = page.locator('#date-button');
await expect(dateButton).toContainText('Oct 23, 2023 - Oct 31, 2023');
});
});

test.describe(title('datetime-button: wheel'), () => {
test('should only show a single date button when presentation="date-time" and prefer-wheel="true"', async ({
page,
Expand Down
5 changes: 5 additions & 0 deletions core/src/components/datetime/datetime-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export type DatetimeHighlight = { date: string } & DatetimeHighlightStyle;

export type DatetimeHighlightCallback = (dateIsoString: string) => DatetimeHighlightStyle | undefined;

export interface DatetimeRangeParts {
start: DatetimeParts;
end?: DatetimeParts;
}

export type DatetimeHourCycle = 'h11' | 'h12' | 'h23' | 'h24';

/**
Expand Down
Loading
Loading