Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

[Date picker] Allow configuring initial month #2498

Merged
merged 4 commits into from
Dec 19, 2022
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

### Dependency updates

## [18.2.3] - 2022-12-16
## [18.3.0] - 2022-12-19

### Added

- `DatePicker`: Allow changing the initialMonth if no date is selected ([@lorgan3](https://github.com/lorgan3)) in ([#2498](https://github.com/teamleadercrm/ui/pull/2498))

### Fixed

Expand Down
7 changes: 6 additions & 1 deletion src/components/datepicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ export interface DatePickerProps extends Omit<BoxProps & DayPickerProps, 'size'
selectedDate?: Date;
/** Size of the DatePicker component. */
size?: Exclude<typeof SIZES[number], 'tiny' | 'fullscreen' | 'hero'>;
/** Show a dropdown for the month? */
withMonthPicker?: boolean;
/** Show week numbers? */
showWeekNumbers?: boolean;
/** The initial month to display if no date is selected. */
initialMonth?: Date;
}

const DatePicker: GenericComponent<DatePickerProps> = ({
Expand All @@ -37,6 +41,7 @@ const DatePicker: GenericComponent<DatePickerProps> = ({
size = 'medium',
withMonthPicker,
showWeekNumbers,
initialMonth,
onChange,
...others
}) => {
Expand Down Expand Up @@ -89,7 +94,7 @@ const DatePicker: GenericComponent<DatePickerProps> = ({
<DayPicker
{...others}
localeUtils={localeUtils}
initialMonth={others.selectedDate}
initialMonth={others.selectedDate ?? initialMonth}
month={selectedMonth}
className={classNames}
classNames={theme as any}
Expand Down
1 change: 1 addition & 0 deletions src/components/datepicker/datePicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ singleDate.args = {
size: 'medium',
withMonthPicker: true,
showWeekNumbers: false,
initialMonth: new Date(),
};
singleDate.parameters = {
design: [
Expand Down