11import classNames from 'classnames' ;
22import ResizeObserver from 'rc-resize-observer' ;
33import { useEvent } from 'rc-util' ;
4+ import omit from 'rc-util/lib/omit' ;
45import * as React from 'react' ;
56import type { RangePickerRef , SelectorProps } from '../../interface' ;
67import PickerContext from '../context' ;
@@ -9,6 +10,7 @@ import useRootProps from './hooks/useRootProps';
910import Icon , { ClearIcon } from './Icon' ;
1011import Input , { type InputRef } from './Input' ;
1112import { getoffsetUnit , getRealPlacement } from '../../utils/uiUtil' ;
13+ import usePrevious from './hooks/usePrevious' ;
1214
1315export type SelectorIdType =
1416 | string
@@ -175,6 +177,7 @@ function RangeSelector<DateType extends object = any>(
175177 // ====================== ActiveBar =======================
176178 const realPlacement = getRealPlacement ( placement , rtl ) ;
177179 const offsetUnit = getoffsetUnit ( realPlacement , rtl ) ;
180+ const prevOffsetUnit = usePrevious < any > ( offsetUnit ) ;
178181 const placementRight = realPlacement ?. toLowerCase ( ) . endsWith ( 'right' ) ;
179182 const [ activeBarStyle , setActiveBarStyle ] = React . useState < React . CSSProperties > ( {
180183 position : 'absolute' ,
@@ -186,12 +189,17 @@ function RangeSelector<DateType extends object = any>(
186189 if ( input ) {
187190 const { offsetWidth, offsetLeft, offsetParent } = input . nativeElement ;
188191 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+ ) ;
195203 onActiveOffset ( activeOffset ) ;
196204 }
197205 } ) ;
0 commit comments