Skip to content

Commit

Permalink
fix: Hacker0x01#4581 and Hacker0x01#4560 selected and preSelection wi…
Browse files Browse the repository at this point in the history
…th showWeekPicker
  • Loading branch information
yuki0410-dev committed Mar 16, 2024
1 parent 72ded5b commit 02f3e8a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 36 deletions.
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 @@ -741,13 +727,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

0 comments on commit 02f3e8a

Please sign in to comment.