@@ -358,7 +358,7 @@ var DateTimeField = (function (_Component) {
358358 var classes = { } ;
359359 var styles = {
360360 display : 'block' ,
361- position : 'absolute '
361+ position : 'fixed '
362362 } ;
363363
364364 if ( options ) {
@@ -368,11 +368,15 @@ var DateTimeField = (function (_Component) {
368368 classes [ 'time' ] = options . timeDisplayed ;
369369 }
370370
371- var wrapRect = _this . wrapper . getBoundingClientRect ( ) ;
372- var widgetRect = _this . widget . getBoundingClientRect ( ) ;
373- var widgetHeight = widgetRect . height ;
374- var fitTop = wrapRect . top - widgetHeight >= 0 ;
375- var fitBottom = document . documentElement . clientHeight > wrapRect . bottom + widgetHeight ;
371+ if ( ! _this . wrapperRef . current || ! _this . widgetRef . current ) {
372+ return ;
373+ }
374+ var fieldRect = _this . wrapperRef . current . getBoundingClientRect ( ) ;
375+ var widgetRect = _this . widgetRef . current . getBoundingClientRect ( ) ;
376+ var arrowIndent = 6 ;
377+ var widgetHeight = widgetRect . height + arrowIndent ;
378+ var fitTop = fieldRect . top - widgetHeight > 0 ;
379+ var fitBottom = fieldRect . bottom + widgetHeight < document . documentElement . clientHeight ;
376380
377381 var placement = _this . props . direction === 'up' || _this . props . direction === 'auto' ? 'top' : 'bottom' ;
378382 var top = placement === 'top' && fitTop || placement === 'bottom' && ! fitBottom ;
@@ -381,10 +385,14 @@ var DateTimeField = (function (_Component) {
381385 if ( top ) {
382386 classes . top = true ;
383387 classes . bottom = false ;
388+ styles . top = fieldRect . top - widgetHeight + 'px' ;
389+ styles . left = fieldRect . left + 'px' ;
384390 }
385391 if ( bottom ) {
386392 classes . top = false ;
387393 classes . bottom = true ;
394+ styles . top = fieldRect . bottom + 'px' ;
395+ styles . left = fieldRect . left + 'px' ;
388396 }
389397
390398 return _this . setState ( {
@@ -460,6 +468,8 @@ var DateTimeField = (function (_Component) {
460468 dateTime = _moment2 [ 'default' ] . utc ( props . dateTime ) ;
461469 }
462470
471+ this . wrapperRef = _react2 [ 'default' ] . createRef ( ) ;
472+ this . widgetRef = _react2 [ 'default' ] . createRef ( ) ;
463473 this . state = {
464474 showDatePicker : props . mode !== _ConstantsJs2 [ 'default' ] . MODE_TIME && props . viewMode !== _ConstantsJs2 [ 'default' ] . MODE_TIME ,
465475 showTimePicker : props . mode === _ConstantsJs2 [ 'default' ] . MODE_TIME || props . viewMode === _ConstantsJs2 [ 'default' ] . MODE_TIME ,
@@ -533,10 +543,7 @@ var DateTimeField = (function (_Component) {
533543 }
534544 return _react2 [ 'default' ] . createElement (
535545 'div' ,
536- { className : pickerClass ,
537- ref : function ( el ) {
538- _this2 . wrapper = el ;
539- } } ,
546+ { ref : this . wrapperRef , className : pickerClass } ,
540547 this . renderOverlay ( ) ,
541548 _react2 [ 'default' ] . createElement ( _DateTimePickerJs2 [ 'default' ] , {
542549 addDecade : this . addDecade ,
@@ -549,9 +556,7 @@ var DateTimeField = (function (_Component) {
549556 minDate : this . props . minDate ,
550557 mode : this . props . mode ,
551558 unlimited : this . props . unlimited ,
552- widgetRef : function ( el ) {
553- return _this2 . widget = el ;
554- } ,
559+ widgetRef : this . widgetRef ,
555560 selectedDate : this . state . selectedDate ,
556561 setSelectedMonth : this . setSelectedMonth ,
557562 setSelectedDate : this . setSelectedDate ,
0 commit comments