Skip to content

Commit 612a369

Browse files
committed
feat(datepicker): Adding support to keepOpenOnSelect prop (defaults to false)
1 parent 5b4d28e commit 612a369

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/components/datepicker.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class SemanticDatepicker extends React.Component {
2828
date: PropTypes.instanceOf(Date),
2929
format: PropTypes.string,
3030
keepOpenOnClear: PropTypes.bool,
31+
keepOpenOnSelect: PropTypes.bool,
3132
locale: PropTypes.object,
3233
onDateChange: PropTypes.func.isRequired,
3334
placeholder: PropTypes.string,
@@ -41,6 +42,7 @@ class SemanticDatepicker extends React.Component {
4142
static defaultProps = {
4243
clearable: true,
4344
keepOpenOnClear: false,
45+
keepOpenOnSelect: false,
4446
date: undefined,
4547
format: 'YYYY-MM-DD',
4648
locale: localeEn,
@@ -147,7 +149,7 @@ class SemanticDatepicker extends React.Component {
147149
};
148150

149151
handleRangeInput = newDates => {
150-
const { format, onDateChange } = this.props;
152+
const { format, keepOpenOnSelect, onDateChange } = this.props;
151153

152154
if (!newDates.length) {
153155
this.resetState();
@@ -164,13 +166,13 @@ class SemanticDatepicker extends React.Component {
164166
onDateChange(newDates);
165167

166168
if (newDates.length === 2) {
167-
this.setState({ isVisible: false });
169+
this.setState({ isVisible: keepOpenOnSelect });
168170
}
169171
});
170172
};
171173

172174
handleBasicInput = newDate => {
173-
const { format, onDateChange } = this.props;
175+
const { format, keepOpenOnSelect, onDateChange } = this.props;
174176

175177
if (!newDate) {
176178
this.resetState();
@@ -179,7 +181,7 @@ class SemanticDatepicker extends React.Component {
179181
}
180182

181183
const newState = {
182-
isVisible: false,
184+
isVisible: keepOpenOnSelect,
183185
selectedDate: newDate,
184186
selectedDateFormatted: formatSelectedDate(newDate, format),
185187
};

0 commit comments

Comments
 (0)