Skip to content

Commit

Permalink
fix(ui): Fix <DatePickerField> closing on click (#13467)
Browse files Browse the repository at this point in the history
The calendar component was closing on any click, this would cause issues when trying to change months. Instead it should stay open until a day is selected.
  • Loading branch information
billyvg authored May 31, 2019
1 parent 89100bd commit c9662e5
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,26 @@ import space from 'app/styles/space';
import InputField from './inputField';

export default class DatePickerField extends React.Component {
onChange = (onChange, onBlur, date) => {
handleChangeDate = (onChange, onBlur, date, close) => {
onChange(date, {});
onBlur(date, {});

// close dropdown menu
close();
};

render() {
return (
<InputField
{...this.props}
field={({onChange, onBlur, value, disabled, name, id, ...props}) => {
field={({onChange, onBlur, value, disabled, name, id}) => {
const dateObj = new Date(value);
const inputValue = !isNaN(dateObj.getTime()) ? dateObj : new Date();
const dateString = moment(inputValue).format('LL');

return (
<DropdownMenu>
{({isOpen, getRootProps, getActorProps, getMenuProps}) => (
<DropdownMenu keepMenuOpen>
{({isOpen, getRootProps, getActorProps, getMenuProps, actions}) => (
<DatePickerWrapper {...getRootProps({isStyled: true})}>
<InputWrapper
name={id}
Expand All @@ -49,7 +52,9 @@ export default class DatePickerField extends React.Component {
<Calendar
disabled={disabled}
date={inputValue}
onChange={date => this.onChange(onChange, onBlur, date)}
onChange={date =>
this.handleChangeDate(onChange, onBlur, date, actions.close)
}
/>
</CalendarMenu>
)}
Expand Down

0 comments on commit c9662e5

Please sign in to comment.