@@ -425,11 +425,11 @@ class Picker extends React.Component {
425
425
if ( isRange ) {
426
426
const updatedInputValue = [ ...inputValue ] ;
427
427
updatedInputValue [ inputType ] = updatedInputValue [ inputType ] + ' ' ;
428
- this . setState ( { inputValue : updatedInputValue } )
428
+ this . setState ( { inputValue : updatedInputValue } ) ;
429
429
} else {
430
430
this . setState ( {
431
- inputValue : inputValue + ' '
432
- } )
431
+ inputValue : inputValue + ' ' ,
432
+ } ) ;
433
433
}
434
434
break ;
435
435
}
@@ -441,7 +441,13 @@ class Picker extends React.Component {
441
441
handleChange = ( v , eventType ) => {
442
442
const { format } = this . props ;
443
443
const { isRange, showOk, value, preValue } = this . state ;
444
- const forceEvents = [ 'KEYDOWN_ENTER' , 'CLICK_PRESET' , 'CLICK_OK' , 'INPUT_CLEAR' , 'VISIBLE_CHANGE' ] ;
444
+ const forceEvents = [
445
+ 'KEYDOWN_ENTER' ,
446
+ 'CLICK_PRESET' ,
447
+ 'CLICK_OK' ,
448
+ 'INPUT_CLEAR' ,
449
+ 'VISIBLE_CHANGE' ,
450
+ ] ;
445
451
const isTemporary = showOk && ! forceEvents . includes ( eventType ) ;
446
452
447
453
// 面板收起时候,将值设置为确认值
@@ -566,15 +572,37 @@ class Picker extends React.Component {
566
572
return left ;
567
573
} ;
568
574
575
+ getRangeInputStartClientRect = ( ) => {
576
+ const rect =
577
+ this . dateInput &&
578
+ this . dateInput . input &&
579
+ this . dateInput . input [ DATE_INPUT_TYPE . BEGIN ] &&
580
+ this . dateInput . input &&
581
+ this . dateInput . input [ DATE_INPUT_TYPE . BEGIN ] . getInputNode ( ) . getBoundingClientRect ( ) ;
582
+ return rect || { } ;
583
+ } ;
584
+
569
585
getPopupOffsetLeft = ( ) => {
570
586
const inputOffsetLeft = this . getRangeInputOffsetLeft ( ) ;
571
587
const popupElement = this . popupRef . current ;
572
588
const popupElementWidth = popupElement ? popupElement . offsetWidth : 0 ;
589
+ // 计算弹层相对于输入框的偏移量
590
+ let { left : inputLeft = 0 } = this . getRangeInputStartClientRect ( ) ;
591
+ const popupElementLeft = popupElement ? popupElement . getBoundingClientRect ( ) . left || 0 : 0 ;
592
+ const offset = popupElementWidth ? Math . round ( Math . abs ( popupElementLeft - inputLeft ) ) : 0 ;
593
+
594
+ // 没有的时候,默认不偏移,要不然会因为 css 中的 transform 属性导致会有偏移动画
595
+ if ( ! popupElementWidth || ( ! inputOffsetLeft && inputOffsetLeft !== 0 ) ) {
596
+ return {
597
+ arrowLeft : 0 ,
598
+ panelLeft : 0 ,
599
+ } ;
600
+ }
573
601
574
602
// 弹层宽度大于输入元素长度,只偏移 arrow
575
603
if ( popupElementWidth > 1.2 * inputOffsetLeft ) {
576
604
return {
577
- arrowLeft : inputOffsetLeft ,
605
+ arrowLeft : inputOffsetLeft + offset ,
578
606
panelLeft : 0 ,
579
607
} ;
580
608
} else {
@@ -587,7 +615,13 @@ class Picker extends React.Component {
587
615
} ;
588
616
589
617
renderArrow = left => {
590
- return < div key = "arrow" className = { `${ this . props . prefix } range-picker2-arrow` } style = { { left } } /> ;
618
+ return (
619
+ < div
620
+ key = "arrow"
621
+ className = { `${ this . props . prefix } range-picker2-arrow` }
622
+ style = { { left } }
623
+ />
624
+ ) ;
591
625
} ;
592
626
593
627
render ( ) {
@@ -641,7 +675,10 @@ class Picker extends React.Component {
641
675
642
676
return (
643
677
< div className = { previewCls } >
644
- { renderNode ( renderPreview , isRange ? inputValue . join ( '-' ) : inputValue , [ curValue , this . props ] ) }
678
+ { renderNode ( renderPreview , isRange ? inputValue . join ( '-' ) : inputValue , [
679
+ curValue ,
680
+ this . props ,
681
+ ] ) }
645
682
</ div >
646
683
) ;
647
684
}
@@ -698,13 +735,20 @@ class Picker extends React.Component {
698
735
} ;
699
736
700
737
const DateNode = isRange ? (
701
- < RangePanel justBeginInput = { justBeginInput } onCalendarChange = { onCalendarChange } { ...panelProps } />
738
+ < RangePanel
739
+ justBeginInput = { justBeginInput }
740
+ onCalendarChange = { onCalendarChange }
741
+ { ...panelProps }
742
+ />
702
743
) : (
703
744
< DatePanel { ...panelProps } />
704
745
) ;
705
746
706
747
// 底部节点
707
- const oKable = ! ! ( ! this . checkValueDisabled ( inputValue ) && ( isRange ? inputValue && inputValue [ inputType ] : inputValue ) ) ;
748
+ const oKable = ! ! (
749
+ ! this . checkValueDisabled ( inputValue ) &&
750
+ ( isRange ? inputValue && inputValue [ inputType ] : inputValue )
751
+ ) ;
708
752
const shouldShowFooter = showOk || preset || extraFooterRender ;
709
753
710
754
const footerNode = shouldShowFooter ? (
@@ -774,7 +818,11 @@ class Picker extends React.Component {
774
818
>
775
819
{ /* eslint-disable-next-line jsx-a11y/no-static-element-interactions */ }
776
820
< div onMouseDown = { handleMouseDown } style = { { marginLeft : panelLeft } } >
777
- < div dir = { rtl ? 'rtl' : undefined } className = { `${ prefixCls } -wrapper` } ref = { this . popupRef } >
821
+ < div
822
+ dir = { rtl ? 'rtl' : undefined }
823
+ className = { `${ prefixCls } -wrapper` }
824
+ ref = { this . popupRef }
825
+ >
778
826
{ isRange ? this . renderArrow ( arrowLeft ) : null }
779
827
{ DateNode }
780
828
{ this . state . panelMode !== this . props . mode ? null : footerNode }
0 commit comments