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

prevent show previous month when using focusSelectedMonth and showPreviousMonths "fix for issue" #3875

Open
michaelfedorov-realcommerce opened this issue Dec 25, 2022 · 4 comments

Comments

@michaelfedorov-realcommerce

Describe the bug
The problem is happen when using focusSelectedMonth = {false} and showPreviousMonths = {false} and monthsShown={2}
the date picker show previous month after clear selected values.
for example: if now December it will be show December, January after clear values it show November, December.
The resolving for the problem I put bottom in section: "How to fix the issue".
Can you fix it and upload in next version ?
If you have another work around for the problem I will be glad if you send me it.

To Reproduce
Steps to reproduce the behavior:

code:

`
import React from "react";
import DatePicker from './DatePicker'

export default class App extends React.Component {

constructor(props) {
    super(props);
    this.state = {
        startDateState: null,
        endDateState: null
    }
    console.log(`constructor`)
}

onChange = (dates) => {
    console.log(`dates`, dates)
    const [start, end] = dates
    console.log(`dates s,e`, start, end)
    this.setState({
        startDateState: start,
        endDateState: end
    });
}


render(){
    return(
        <div>
            <DatePicker 
                isClearable
                onChange={this.onChange}
                selectsRange
                focusSelectedMonth={false}
                monthsShown={2}
                minDate={new Date()}
                startDate={this.state.startDateState}
                endDate={this.state.endDateState}
                shouldCloseOnSelect={false}
                showPreviousMonths={false}
                selected={this.state.startDateState}
            />
        </div>
    )
}

}
`

  1. Go to 'datepicker'
  2. Click on 'input value select range on dates'
  3. close date picker
  4. click on "x" clean input values
  5. click on input value

Expected behavior
show previous month, instead to show December, January show November, December

Screenshots
before:
image

after clean:
image

How to fix the issue
I find the problem in package.
Need to set default value to method:
src -> DatePicker.jsx -> DatePicker -> onClearClick
set default value for monthSelectedIn
method code:

`
onClearClick = (event) => {
if (event) {
if (event.preventDefault) {
event.preventDefault();
}
}
if (this.props.selectsRange) {
this.props.onChange([null, null], event);
} else {
this.props.onChange(null, event);
}
this.setState({ monthSelectedIn: 0 });
this.setState({ inputValue: null });
};

`

Thanks Michael

@batuhannozenn
Copy link

I got same problem here, is there any fix for it ?

@carakessler
Copy link

Same

@nikosroussounelos
Copy link

Same here, any updates?

@RomanChuchval
Copy link

Same, there is a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants