@@ -37,6 +37,7 @@ import useState from '../_util/hooks/useState';
37
37
import classNames from '../_util/classNames' ;
38
38
import { useProviderTrigger } from '../vc-trigger/context' ;
39
39
import { legacyPropsWarning } from './utils/warnUtil' ;
40
+ import { useElementSize } from '../_util/hooks/_vueuse/useElementSize' ;
40
41
41
42
function reorderValues < DateType > (
42
43
values : RangeValue < DateType > ,
@@ -372,15 +373,55 @@ function RangerPicker<DateType>() {
372
373
373
374
const startOpen = computed ( ( ) => mergedOpen . value && mergedActivePickerIndex . value === 0 ) ;
374
375
const endOpen = computed ( ( ) => mergedOpen . value && mergedActivePickerIndex . value === 1 ) ;
375
-
376
+ const panelLeft = ref ( 0 ) ;
377
+ const arrowLeft = ref ( 0 ) ;
376
378
// ============================= Popup =============================
377
379
// Popup min width
378
380
const popupMinWidth = ref ( 0 ) ;
379
- watch ( mergedOpen , ( ) => {
381
+ const { width : containerWidth } = useElementSize ( containerRef ) ;
382
+ watch ( [ mergedOpen , containerWidth ] , ( ) => {
380
383
if ( ! mergedOpen . value && containerRef . value ) {
381
- popupMinWidth . value = containerRef . value . offsetWidth ;
384
+ popupMinWidth . value = containerWidth . value ;
382
385
}
383
386
} ) ;
387
+ const { width : panelDivWidth } = useElementSize ( panelDivRef ) ;
388
+ const { width : arrowWidth } = useElementSize ( arrowRef ) ;
389
+ const { width : startInputDivWidth } = useElementSize ( startInputDivRef ) ;
390
+ const { width : separatorWidth } = useElementSize ( separatorRef ) ;
391
+ watch (
392
+ [
393
+ mergedActivePickerIndex ,
394
+ mergedOpen ,
395
+ panelDivWidth ,
396
+ arrowWidth ,
397
+ startInputDivWidth ,
398
+ separatorWidth ,
399
+ ( ) => props . direction ,
400
+ ] ,
401
+ ( ) => {
402
+ arrowLeft . value = 0 ;
403
+ if ( mergedOpen . value && mergedActivePickerIndex . value ) {
404
+ if ( startInputDivRef . value && separatorRef . value && panelDivRef . value ) {
405
+ arrowLeft . value = startInputDivWidth . value + separatorWidth . value ;
406
+ if (
407
+ panelDivWidth . value &&
408
+ arrowWidth . value &&
409
+ arrowLeft . value >
410
+ panelDivWidth . value -
411
+ arrowWidth . value -
412
+ ( props . direction === 'rtl' || arrowRef . value . offsetLeft > arrowLeft . value
413
+ ? 0
414
+ : arrowRef . value . offsetLeft )
415
+ ) {
416
+ panelLeft . value = arrowLeft . value ;
417
+ }
418
+ }
419
+ } else if ( mergedActivePickerIndex . value === 0 ) {
420
+ panelLeft . value = 0 ;
421
+ }
422
+ } ,
423
+ { immediate : true } ,
424
+ ) ;
384
425
385
426
// ============================ Trigger ============================
386
427
const triggerRef = ref < any > ( ) ;
@@ -981,32 +1022,11 @@ function RangerPicker<DateType>() {
981
1022
direction,
982
1023
autocomplete = 'off' ,
983
1024
} = props ;
984
- let arrowLeft = 0 ;
985
- let panelLeft = 0 ;
986
- if (
987
- mergedActivePickerIndex . value &&
988
- startInputDivRef . value &&
989
- separatorRef . value &&
990
- panelDivRef . value
991
- ) {
992
- // Arrow offset
993
- arrowLeft = startInputDivRef . value . offsetWidth + separatorRef . value . offsetWidth ;
994
- if (
995
- panelDivRef . value . offsetWidth &&
996
- arrowRef . value . offsetWidth &&
997
- arrowLeft >
998
- panelDivRef . value . offsetWidth -
999
- arrowRef . value . offsetWidth -
1000
- ( direction === 'rtl' || arrowRef . value . offsetLeft > arrowLeft
1001
- ? 0
1002
- : arrowRef . value . offsetLeft )
1003
- ) {
1004
- panelLeft = arrowLeft ;
1005
- }
1006
- }
1007
1025
1008
1026
const arrowPositionStyle =
1009
- direction === 'rtl' ? { right : `${ arrowLeft } px` } : { left : `${ arrowLeft } px` } ;
1027
+ direction === 'rtl'
1028
+ ? { right : `${ arrowLeft . value } px` }
1029
+ : { left : `${ arrowLeft . value } px` } ;
1010
1030
1011
1031
function renderPanels ( ) {
1012
1032
let panels : VueNode ;
@@ -1097,7 +1117,7 @@ function RangerPicker<DateType>() {
1097
1117
return (
1098
1118
< div
1099
1119
class = { `${ prefixCls } -panel-container` }
1100
- style = { { marginLeft : `${ panelLeft } px` } }
1120
+ style = { { marginLeft : `${ panelLeft . value } px` } }
1101
1121
ref = { panelDivRef }
1102
1122
onMousedown = { e => {
1103
1123
e . preventDefault ( ) ;
@@ -1168,7 +1188,7 @@ function RangerPicker<DateType>() {
1168
1188
if ( mergedActivePickerIndex . value === 0 ) {
1169
1189
activeBarWidth = startInputDivRef . value . offsetWidth ;
1170
1190
} else {
1171
- activeBarLeft = arrowLeft ;
1191
+ activeBarLeft = arrowLeft . value ;
1172
1192
activeBarWidth = endInputDivRef . value . offsetWidth ;
1173
1193
}
1174
1194
}
0 commit comments