Skip to content
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
17 changes: 1 addition & 16 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,26 +296,11 @@ class SemanticDatepicker extends React.Component<
format,
keepOpenOnSelect,
onChange,
clearOnSameDateClick,
formatOptions,
} = this.props;

if (!newDate) {
// if clearOnSameDateClick is true (this is the default case)
// then reset the state. This is what was previously the default
// behavior, without a specific prop.
if (clearOnSameDateClick) {
this.resetState(event);
} else {
// Don't reset the state. Instead, close or keep open the
// datepicker according to the value of keepOpenOnSelect.
// Essentially, follow the default behavior of clicking a date
// but without changing the value in state.
this.setState({
isVisible: keepOpenOnSelect,
});
}

this.resetState(event);
return;
}

Expand Down
8 changes: 6 additions & 2 deletions src/pickers/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ class DatePicker extends React.Component<BasicDatePickerProps> {
{ selectable, date },
event: React.SyntheticEvent
) => {
const { selected: selectedDate, onChange } = this.props;
const { clearOnSameDateClick, selected: selectedDate, onChange } = this.props;

if (!selectable) {
return;
}

let newDate = date;
if (selectedDate && selectedDate.getTime() === date.getTime()) {
if (
selectedDate &&
selectedDate.getTime() === date.getTime() &&
clearOnSameDateClick
) {
newDate = null;
}

Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export type BaseDatePickerProps = DayzedProps & {
};

export interface BasicDatePickerProps extends BaseDatePickerProps {
clearOnSameDateClick?: boolean
onChange: (event: React.SyntheticEvent, date: Date | null) => void;
selected: Date;
}
Expand Down