@@ -9,6 +9,7 @@ import useRootProps from './hooks/useRootProps';
9
9
import Icon , { ClearIcon } from './Icon' ;
10
10
import Input , { type InputRef } from './Input' ;
11
11
import { getoffsetUnit , getRealPlacement } from '../../utils/uiUtil' ;
12
+ import { getWin } from './util' ;
12
13
13
14
export type SelectorIdType =
14
15
| string
@@ -184,13 +185,26 @@ function RangeSelector<DateType extends object = any>(
184
185
const syncActiveOffset = useEvent ( ( ) => {
185
186
const input = getInput ( activeIndex ) ;
186
187
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 ;
190
203
setActiveBarStyle ( ( { position } ) => ( {
191
204
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 ,
194
208
} ) ) ;
195
209
onActiveOffset ( activeOffset ) ;
196
210
}
0 commit comments