Skip to content

Commit 07cc938

Browse files
authored
fix(datepicker): reset state properly when clearOnSameDateClick is false (#706)
1 parent f0c1707 commit 07cc938

File tree

3 files changed

+8
-18
lines changed

3 files changed

+8
-18
lines changed

src/index.tsx

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -296,26 +296,11 @@ class SemanticDatepicker extends React.Component<
296296
format,
297297
keepOpenOnSelect,
298298
onChange,
299-
clearOnSameDateClick,
300299
formatOptions,
301300
} = this.props;
302301

303302
if (!newDate) {
304-
// if clearOnSameDateClick is true (this is the default case)
305-
// then reset the state. This is what was previously the default
306-
// behavior, without a specific prop.
307-
if (clearOnSameDateClick) {
308-
this.resetState(event);
309-
} else {
310-
// Don't reset the state. Instead, close or keep open the
311-
// datepicker according to the value of keepOpenOnSelect.
312-
// Essentially, follow the default behavior of clicking a date
313-
// but without changing the value in state.
314-
this.setState({
315-
isVisible: keepOpenOnSelect,
316-
});
317-
}
318-
303+
this.resetState(event);
319304
return;
320305
}
321306

src/pickers/basic.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ class DatePicker extends React.Component<BasicDatePickerProps> {
77
{ selectable, date },
88
event: React.SyntheticEvent
99
) => {
10-
const { selected: selectedDate, onChange } = this.props;
10+
const { clearOnSameDateClick, selected: selectedDate, onChange } = this.props;
1111

1212
if (!selectable) {
1313
return;
1414
}
1515

1616
let newDate = date;
17-
if (selectedDate && selectedDate.getTime() === date.getTime()) {
17+
if (
18+
selectedDate &&
19+
selectedDate.getTime() === date.getTime() &&
20+
clearOnSameDateClick
21+
) {
1822
newDate = null;
1923
}
2024

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export type BaseDatePickerProps = DayzedProps & {
9999
};
100100

101101
export interface BasicDatePickerProps extends BaseDatePickerProps {
102+
clearOnSameDateClick?: boolean
102103
onChange: (event: React.SyntheticEvent, date: Date | null) => void;
103104
selected: Date;
104105
}

0 commit comments

Comments
 (0)