@@ -122,14 +122,23 @@ export default function useAlign(
122122 popupElement . style . top = '0' ;
123123
124124 // Calculate align style, we should consider `transform` case
125- const targetRect = Array . isArray ( target )
126- ? {
127- x : target [ 0 ] ,
128- y : target [ 1 ] ,
129- width : 0 ,
130- height : 0 ,
131- }
132- : target . getBoundingClientRect ( ) ;
125+ let targetRect : Rect ;
126+ if ( Array . isArray ( target ) ) {
127+ targetRect = {
128+ x : target [ 0 ] ,
129+ y : target [ 1 ] ,
130+ width : 0 ,
131+ height : 0 ,
132+ } ;
133+ } else {
134+ const rect = target . getBoundingClientRect ( ) ;
135+ targetRect = {
136+ x : rect . x ,
137+ y : rect . y ,
138+ width : rect . width ,
139+ height : rect . height ,
140+ } ;
141+ }
133142 const popupRect = popupElement . getBoundingClientRect ( ) ;
134143 const { width, height } = win . getComputedStyle ( popupElement ) ;
135144 const { clientWidth, clientHeight } = doc . documentElement ;
@@ -152,6 +161,16 @@ export default function useAlign(
152161 // Placement
153162 const placementInfo : AlignType =
154163 builtinPlacements [ placement ] || popupAlign || { } ;
164+
165+ // Offset
166+ const { offset, targetOffset } = placementInfo ;
167+ const [ popupOffsetX = 0 , popupOffsetY = 0 ] = offset || [ ] ;
168+ const [ targetOffsetX = 0 , targetOffsetY = 0 ] = targetOffset || [ ] ;
169+
170+ targetRect . x += targetOffsetX ;
171+ targetRect . y += targetOffsetY ;
172+
173+ // Points
155174 const [ popupPoint , targetPoint ] = placementInfo . points || [ ] ;
156175 const targetPoints = splitPoints ( targetPoint ) ;
157176 const popupPoints = splitPoints ( popupPoint ) ;
@@ -164,11 +183,7 @@ export default function useAlign(
164183 ...placementInfo ,
165184 } ;
166185
167- // Offset
168- const { offset } = placementInfo ;
169- const [ popupOffsetX = 0 , popupOffsetY = 0 ] = offset || [ ] ;
170-
171- // Placement
186+ // Next Offset
172187 let nextOffsetX = targetAlignPoint . x - popupAlignPoint . x + popupOffsetX ;
173188 let nextOffsetY = targetAlignPoint . y - popupAlignPoint . y + popupOffsetY ;
174189
0 commit comments