@@ -9,6 +9,7 @@ import useRootProps from './hooks/useRootProps';
99import Icon , { ClearIcon } from './Icon' ;
1010import Input , { type InputRef } from './Input' ;
1111import { getoffsetUnit , getRealPlacement } from '../../utils/uiUtil' ;
12+ import { getWin } from './util' ;
1213
1314export type SelectorIdType =
1415 | string
@@ -184,13 +185,26 @@ function RangeSelector<DateType extends object = any>(
184185 const syncActiveOffset = useEvent ( ( ) => {
185186 const input = getInput ( activeIndex ) ;
186187 if ( input ) {
187- const { offsetWidth, offsetLeft, offsetParent } = input . nativeElement ;
188- const parentWidth = ( offsetParent as HTMLElement ) ?. offsetWidth || 0 ;
189- const activeOffset = placementRight ? parentWidth - offsetWidth - offsetLeft : offsetLeft ;
188+ const { offsetParent } = input . nativeElement ;
189+ // offsetLeft is an integer, which will cause incorrect reulst.
190+ const { x = 0 , width : inputWidth = 0 } = input . nativeElement . getBoundingClientRect ( ) || { } ;
191+ const { x : pX = 0 , width : parentWidth = 0 } = offsetParent ?. getBoundingClientRect ( ) || { } ;
192+ const parentStyles =
193+ offsetParent && getWin ( offsetParent as HTMLElement ) . getComputedStyle ( offsetParent ) ;
194+ const parentBorderRightWidth = Number (
195+ ( placementRight ? parentStyles ?. borderRightWidth : parentStyles ?. borderLeftWidth ) ?. replace (
196+ 'px' ,
197+ '' ,
198+ ) || 0 ,
199+ ) ;
200+ const offsetLeft = x - pX ;
201+
202+ const activeOffset = placementRight ? parentWidth - inputWidth - offsetLeft : offsetLeft ;
190203 setActiveBarStyle ( ( { position } ) => ( {
191204 position,
192- width : offsetWidth ,
193- [ offsetUnit ] : activeOffset ,
205+ width : inputWidth ,
206+ // parent will have border while focus, so need to cut `parentBorderWidth` on opposite side.
207+ [ offsetUnit ] : activeOffset - parentBorderRightWidth ,
194208 } ) ) ;
195209 onActiveOffset ( activeOffset ) ;
196210 }
0 commit comments