Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #4581 and #4560 selected and preSelection with showWeekPicker #4601

Merged
merged 1 commit into from
Mar 16, 2024
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
21 changes: 0 additions & 21 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,6 @@ export default class DatePicker extends React.Component {
});
}
if (date || !event.target.value) {
if (this.props.showWeekPicker) {
date = getStartOfWeek(
date,
this.props.locale,
this.props.calendarStartDay,
);
}
this.setSelected(date, event, true);
}
};
Expand All @@ -593,13 +586,6 @@ export default class DatePicker extends React.Component {
if (this.props.onChangeRaw) {
this.props.onChangeRaw(event);
}
if (this.props.showWeekPicker) {
date = getStartOfWeek(
date,
this.props.locale,
this.props.calendarStartDay,
);
}
this.setSelected(date, event, false, monthSelectedIn);
if (this.props.showDateSelect) {
this.setState({ isRenderAriaLiveMessage: true });
Expand Down Expand Up @@ -743,13 +729,6 @@ export default class DatePicker extends React.Component {
const hasMaxDate = typeof this.props.maxDate !== "undefined";
let isValidDateSelection = true;
if (date) {
if (this.props.showWeekPicker) {
date = getStartOfWeek(
date,
this.props.locale,
this.props.calendarStartDay,
);
}
const dateStartOfDay = startOfDay(date);
if (hasMinDate && hasMaxDate) {
// isDayInRange uses startOfDay internally, so not necessary to manipulate times here
Expand Down
20 changes: 18 additions & 2 deletions src/month.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,22 @@ export default class Month extends React.Component {
this.props.calendarStartDay,
);

const selected = this.props.showWeekPicker
? utils.getStartOfWeek(
this.props.selected,
this.props.locale,
this.props.calendarStartDay,
)
: this.props.selected;

const preSelection = this.props.showWeekPicker
? utils.getStartOfWeek(
this.props.preSelection,
this.props.locale,
this.props.calendarStartDay,
)
: this.props.preSelection;

while (true) {
weeks.push(
<Week
Expand Down Expand Up @@ -337,8 +353,8 @@ export default class Month extends React.Component {
holidays={this.props.holidays}
selectingDate={this.props.selectingDate}
filterDate={this.props.filterDate}
preSelection={this.props.preSelection}
selected={this.props.selected}
preSelection={preSelection}
selected={selected}
selectsStart={this.props.selectsStart}
selectsEnd={this.props.selectsEnd}
selectsRange={this.props.selectsRange}
Expand Down
13 changes: 2 additions & 11 deletions src/week.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,7 @@ export default class Week extends React.Component {
this.props.onWeekSelect(day, weekNumber, event);
}
if (this.props.showWeekPicker) {
const startOfWeek = getStartOfWeek(
day,
this.props.locale,
this.props.calendarStartDay,
);
this.handleDayClick(startOfWeek, event);
this.handleDayClick(day, event);
}
if (this.props.shouldCloseOnSelect) {
this.props.setOpen(false);
Expand All @@ -117,11 +112,7 @@ export default class Week extends React.Component {
};

renderDays = () => {
const startOfWeek = getStartOfWeek(
this.props.day,
this.props.locale,
this.props.calendarStartDay,
);
const startOfWeek = this.startOfWeek();
const days = [];
const weekNumber = this.formatWeekNumber(startOfWeek);
if (this.props.showWeekNumber) {
Expand Down
3 changes: 1 addition & 2 deletions test/week_test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ describe("Week", () => {
);
const handleDayClick = jest.spyOn(instance, "handleDayClick");
instance.handleWeekClick(day, weekNumber, event);
const startOfWeek = utils.getStartOfWeek(day);
expect(handleDayClick).toHaveBeenCalledWith(startOfWeek, event);
expect(handleDayClick).toHaveBeenCalledWith(day, event);
});

it("should call setOpen prop with false if shouldCloseOnSelect prop is true", () => {
Expand Down
Loading