Skip to content

Commit 81760d4

Browse files
committed
feat(datepicker): improved default behavior for multiple date selections
1 parent 30babb9 commit 81760d4

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/date_utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,21 @@ export function safeDateRangeFormat(
305305
*/
306306
export function safeMultipleDatesFormat(
307307
dates: Date[],
308-
props: { dateFormat: string | string[]; locale?: Locale },
308+
props: {
309+
dateFormat: string | string[];
310+
locale?: Locale;
311+
showCount?: boolean;
312+
},
309313
): string {
310314
if (!dates?.length) {
311315
return "";
312316
}
313317

318+
if (props?.showCount === false) {
319+
const formattedAllDates = dates.map((date) => safeDateFormat(date, props));
320+
return formattedAllDates.join(", ");
321+
}
322+
314323
const formattedFirstDate = dates[0] ? safeDateFormat(dates[0], props) : "";
315324
if (dates.length === 1) {
316325
return formattedFirstDate;

src/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export type DatePickerProps = OmitUnion<
206206
| {
207207
selectsRange?: never;
208208
selectsMultiple?: never;
209+
showCount?: never;
209210
onChange?: (
210211
date: Date | null,
211212
event?:
@@ -216,6 +217,7 @@ export type DatePickerProps = OmitUnion<
216217
| {
217218
selectsRange: true;
218219
selectsMultiple?: never;
220+
showCount?: never;
219221
onChange?: (
220222
date: [Date | null, Date | null],
221223
event?:
@@ -226,6 +228,7 @@ export type DatePickerProps = OmitUnion<
226228
| {
227229
selectsRange?: never;
228230
selectsMultiple: true;
231+
showCount?: boolean;
229232
onChange?: (
230233
date: Date[] | null,
231234
event?:
@@ -301,6 +304,7 @@ export default class DatePicker extends Component<
301304
calendarStartDay: undefined,
302305
toggleCalendarOnIconClick: false,
303306
usePointerEvent: false,
307+
showCount: true,
304308
};
305309
}
306310

@@ -1337,8 +1341,11 @@ export default class DatePicker extends Component<
13371341

13381342
const customInput = this.props.customInput || <input type="text" />;
13391343
const customInputRef = this.props.customInputRef || "ref";
1340-
const { dateFormat = DatePicker.defaultProps.dateFormat, locale } =
1341-
this.props;
1344+
const {
1345+
dateFormat = DatePicker.defaultProps.dateFormat,
1346+
locale,
1347+
showCount = DatePicker.defaultProps.showCount,
1348+
} = this.props;
13421349
const inputValue =
13431350
typeof this.props.value === "string"
13441351
? this.props.value
@@ -1353,6 +1360,7 @@ export default class DatePicker extends Component<
13531360
? safeMultipleDatesFormat(this.props.selectedDates ?? [], {
13541361
dateFormat,
13551362
locale,
1363+
showCount,
13561364
})
13571365
: safeDateFormat(this.props.selected, {
13581366
dateFormat,

0 commit comments

Comments
 (0)