diff --git a/css/DateRangePicker.scss b/css/DateRangePicker.scss index 3cfdaee93d..03059f8f20 100644 --- a/css/DateRangePicker.scss +++ b/css/DateRangePicker.scss @@ -23,14 +23,6 @@ top: $react-dates-spacing-vertical-picker; } -.DateRangePicker__picker--show { - visibility: visible; -} - -.DateRangePicker__picker--invisible { - visibility: hidden; -} - .DateRangePicker__picker--direction-left { left: 0; } diff --git a/css/SingleDatePicker.scss b/css/SingleDatePicker.scss index ffcbf7aaa3..a1d4b79a0e 100644 --- a/css/SingleDatePicker.scss +++ b/css/SingleDatePicker.scss @@ -12,14 +12,6 @@ top: $react-dates-spacing-vertical-picker; } -.SingleDatePicker__picker--show { - visibility: visible; -} - -.SingleDatePicker__picker--invisible { - visibility: hidden; -} - .SingleDatePicker__picker--direction-left { left: 0; } diff --git a/src/components/DateRangePicker.jsx b/src/components/DateRangePicker.jsx index 5344465ed9..06cbaf5569 100644 --- a/src/components/DateRangePicker.jsx +++ b/src/components/DateRangePicker.jsx @@ -92,30 +92,32 @@ export default class DateRangePicker extends React.Component { return shallowCompare(this, nextProps, nextState); } + componentDidUpdate(prevProps) { + if (!prevProps.focusedInput && this.props.focusedInput && this.isOpened()) { + // The date picker just changed from being closed to being open. + this.responsivizePickerPosition(); + } + } + componentWillUnmount() { window.removeEventListener('resize', this.responsivizePickerPosition); } onOutsideClick() { - const { focusedInput, onFocusChange } = this.props; - if (!focusedInput) return; + const { onFocusChange } = this.props; + if (!this.isOpened()) return; onFocusChange(null); } getDayPickerContainerClasses() { const { - focusedInput, orientation, withPortal, withFullScreenPortal, anchorDirection, } = this.props; - const showDatepicker = focusedInput === START_DATE || focusedInput === END_DATE; - const dayPickerClassName = cx('DateRangePicker__picker', { - 'DateRangePicker__picker--show': showDatepicker, - 'DateRangePicker__picker--invisible': !showDatepicker, 'DateRangePicker__picker--direction-left': anchorDirection === ANCHOR_LEFT, 'DateRangePicker__picker--direction-right': anchorDirection === ANCHOR_RIGHT, 'DateRangePicker__picker--horizontal': orientation === HORIZONTAL_ORIENTATION, @@ -131,7 +133,16 @@ export default class DateRangePicker extends React.Component { return ReactDOM.findDOMNode(this.dayPicker); } + isOpened() { + const { focusedInput } = this.props; + return focusedInput === START_DATE || focusedInput === END_DATE; + } + responsivizePickerPosition() { + if (!this.isOpened()) { + return; + } + const { anchorDirection, horizontalMargin, withPortal, withFullScreenPortal } = this.props; const { dayPickerContainerStyles } = this.state; @@ -154,11 +165,15 @@ export default class DateRangePicker extends React.Component { } maybeRenderDayPickerWithPortal() { - const { focusedInput, withPortal, withFullScreenPortal } = this.props; + const { withPortal, withFullScreenPortal } = this.props; + + if (!this.isOpened()) { + return null; + } if (withPortal || withFullScreenPortal) { return ( - + {this.renderDayPicker()} ); @@ -193,7 +208,9 @@ export default class DateRangePicker extends React.Component { } = this.props; const { dayPickerContainerStyles } = this.state; - const onOutsideClick = (!withFullScreenPortal && withPortal) ? this.onOutsideClick : undefined; + const onOutsideClick = (!withFullScreenPortal && withPortal) + ? this.onOutsideClick + : undefined; return (