DatePicker fires onSelectDate event twice when allowTextInput is set to true
Environment Information
- Package version(s):
- 6.110.2 and 6.117.2
- Browser and OS versions:
- Chrome Version 71.0.3578.98 (Official Build) (64-bit)
- Windows 10 Enterprise 64 bit
Please provide a reproduction of the bug in a codepen:
Actual behavior:
- Set the DatePicker to have the initial date (set it's value property). Say -12/26/2018
- Make sure allowTextInput is set to true
- I also set isMonthPickerVisible=false. Not sure if this matters though.
- Open datepicker and change it to 12/28/2018
- onSelectDate is fired twice with newly selected date value ie 12/28/2018
Code pen: https://codepen.io/subashbhujel/pen/yGoeMG
Expected behavior:
onSelectDate should be fired only ONCE.
Priorities and help requested:
Are you willing to submit a PR to fix? No
Requested priority: Normal
Products/sites affected: (if applicable)
Thanks for reporting this issue. The first callback happens as soon as the date is chosen using the Calendar popup, the second when the value is validated. I see three possible solutions to this issue:
- First option, add another value to the
onSelectedDate, lets say 'isValidated'. The value will help distinguish between two fires. The definition will be updated toonSelectDate?: (date, isValidated) => void;. This one might be the most safest - Or, in case when Calendar popup is used, don't fire the first event and only fire when the value is validated
- Or, in case when Calendar popup is used, don't validate and just fire the first event
@OfficeDev/uifabric-calendar
@lorejoh12
@kenotron whats the reason to call validateTextInput when the Calendar popup is dismissed? We can't change text if the popup is open anyways as the focus is trapped in the popup. And I think we can rely on the fact that popup gives us correct date.
https://github.com/OfficeDev/office-ui-fabric-react/blob/9ae54921bc0b1cfb55001f53824acd813fadb49a/packages/office-ui-fabric-react/src/components/DatePicker/DatePicker.base.tsx#L387
It passes tests if I remove it, and I couldn't come up with a case when it will be needed.
Here is last merge https://github.com/OfficeDev/office-ui-fabric-react/pull/6999
:tada:This issue was addressed in #7559, which has now been successfully released as [email protected].:tada:
Handy links: