1
1
import classNames from 'classnames' ;
2
2
import ResizeObserver from 'rc-resize-observer' ;
3
3
import { useEvent } from 'rc-util' ;
4
+ import omit from 'rc-util/lib/omit' ;
4
5
import * as React from 'react' ;
5
6
import type { RangePickerRef , SelectorProps } from '../../interface' ;
6
7
import PickerContext from '../context' ;
@@ -9,6 +10,7 @@ import useRootProps from './hooks/useRootProps';
9
10
import Icon , { ClearIcon } from './Icon' ;
10
11
import Input , { type InputRef } from './Input' ;
11
12
import { getoffsetUnit , getRealPlacement } from '../../utils/uiUtil' ;
13
+ import usePrevious from './hooks/usePrevious' ;
12
14
13
15
export type SelectorIdType =
14
16
| string
@@ -175,6 +177,7 @@ function RangeSelector<DateType extends object = any>(
175
177
// ====================== ActiveBar =======================
176
178
const realPlacement = getRealPlacement ( placement , rtl ) ;
177
179
const offsetUnit = getoffsetUnit ( realPlacement , rtl ) ;
180
+ const prevOffsetUnit = usePrevious < any > ( offsetUnit ) ;
178
181
const placementRight = realPlacement ?. toLowerCase ( ) . endsWith ( 'right' ) ;
179
182
const [ activeBarStyle , setActiveBarStyle ] = React . useState < React . CSSProperties > ( {
180
183
position : 'absolute' ,
@@ -186,12 +189,17 @@ function RangeSelector<DateType extends object = any>(
186
189
if ( input ) {
187
190
const { offsetWidth, offsetLeft, offsetParent } = input . nativeElement ;
188
191
const parentWidth = ( offsetParent as HTMLElement ) ?. offsetWidth || 0 ;
189
- const activeOffset = placementRight ? ( parentWidth - offsetWidth - offsetLeft ) : offsetLeft ;
190
- setActiveBarStyle ( ( ori ) => ( {
191
- ...ori ,
192
- width : offsetWidth ,
193
- [ offsetUnit ] : activeOffset ,
194
- } ) ) ;
192
+ const activeOffset = placementRight ? parentWidth - offsetWidth - offsetLeft : offsetLeft ;
193
+ setActiveBarStyle ( ( ori ) =>
194
+ omit (
195
+ {
196
+ ...ori ,
197
+ width : offsetWidth ,
198
+ [ offsetUnit ] : activeOffset ,
199
+ } ,
200
+ [ prevOffsetUnit ] ,
201
+ ) ,
202
+ ) ;
195
203
onActiveOffset ( activeOffset ) ;
196
204
}
197
205
} ) ;
0 commit comments