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

Add clickUnselectsDay prop #411

Merged
merged 1 commit into from
Jun 16, 2017
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
5 changes: 4 additions & 1 deletion src/DayPickerInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default class DayPickerInput extends React.Component {
format: PropTypes.string.isRequired,
dayPickerProps: PropTypes.object,
hideOnDayClick: PropTypes.bool,
clickUnselectDay: PropTypes.bool,
component: PropTypes.any,

classNames: PropTypes.shape({
Expand All @@ -57,6 +58,7 @@ export default class DayPickerInput extends React.Component {
value: '',
format: 'L',
hideOnDayClick: true,
clickUnselectDay: false,
component: 'input',
classNames: {
container: 'DayPickerInput',
Expand Down Expand Up @@ -216,7 +218,7 @@ export default class DayPickerInput extends React.Component {
// Do nothing if the day is disabled
return;
}
if (modifiers.selected) {
if (modifiers.selected && this.props.clickUnselectDay) {
// Unselect the day
this.setState({ value: '' }, this.hideAfterDayClick);
if (this.props.onDayChange) {
Expand Down Expand Up @@ -265,6 +267,7 @@ export default class DayPickerInput extends React.Component {
delete inputProps.component;
delete inputProps.dayPickerProps;
delete inputProps.format;
delete inputProps.clickUnselectDay;
delete inputProps.hideOnDayClick;
delete inputProps.onDayChange;
delete inputProps.classNames;
Expand Down
2 changes: 2 additions & 0 deletions test/daypickerinput/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ describe('DayPickerInput', () => {
const wrapper = mount(
<DayPickerInput
value="02/08/2017"
clickUnselectDay
dayPickerProps={{
month: new Date(2017, 1),
selectedDays: new Date(2017, 1, 8),
Expand All @@ -219,6 +220,7 @@ describe('DayPickerInput', () => {
<DayPickerInput
value="02/08/2017"
onDayChange={onDayChange}
clickUnselectDay
dayPickerProps={{
month: new Date(2017, 1),
selectedDays: new Date(2017, 1, 8),
Expand Down