@@ -9,16 +9,12 @@ import type {
9
9
AlignPointTopBottom ,
10
10
AlignType ,
11
11
} from '../interface' ;
12
- import { collectScroller , getWin } from '../util' ;
12
+ import { collectScroller , getVisibleArea , getWin , toNum } from '../util' ;
13
13
14
14
type Rect = Record < 'x' | 'y' | 'width' | 'height' , number > ;
15
15
16
16
type Points = [ topBottom : AlignPointTopBottom , leftRight : AlignPointLeftRight ] ;
17
17
18
- function toNum ( num : number ) {
19
- return Number . isNaN ( num ) ? 1 : num ;
20
- }
21
-
22
18
function splitPoints ( points : string = '' ) : Points {
23
19
return [ points [ 0 ] as any , points [ 1 ] as any ] ;
24
20
}
@@ -174,7 +170,7 @@ export default function useAlign(
174
170
const targetWidth = targetRect . width ;
175
171
176
172
// Get bounding of visible area
177
- const visibleArea =
173
+ let visibleArea =
178
174
placementInfo . htmlRegion === 'scroll'
179
175
? // Scroll region should take scrollLeft & scrollTop into account
180
176
{
@@ -190,36 +186,7 @@ export default function useAlign(
190
186
bottom : clientHeight ,
191
187
} ;
192
188
193
- ( scrollerList || [ ] ) . forEach ( ( ele ) => {
194
- if ( ele instanceof HTMLBodyElement ) {
195
- return ;
196
- }
197
-
198
- const eleRect = ele . getBoundingClientRect ( ) ;
199
- const {
200
- offsetHeight : eleOutHeight ,
201
- clientHeight : eleInnerHeight ,
202
- offsetWidth : eleOutWidth ,
203
- clientWidth : eleInnerWidth ,
204
- } = ele ;
205
-
206
- const scaleX = toNum (
207
- Math . round ( ( eleRect . width / eleOutWidth ) * 1000 ) / 1000 ,
208
- ) ;
209
- const scaleY = toNum (
210
- Math . round ( ( eleRect . height / eleOutHeight ) * 1000 ) / 1000 ,
211
- ) ;
212
-
213
- const eleScrollWidth = ( eleOutWidth - eleInnerWidth ) * scaleX ;
214
- const eleScrollHeight = ( eleOutHeight - eleInnerHeight ) * scaleY ;
215
- const eleRight = eleRect . x + eleRect . width - eleScrollWidth ;
216
- const eleBottom = eleRect . y + eleRect . height - eleScrollHeight ;
217
-
218
- visibleArea . left = Math . max ( visibleArea . left , eleRect . left ) ;
219
- visibleArea . top = Math . max ( visibleArea . top , eleRect . top ) ;
220
- visibleArea . right = Math . min ( visibleArea . right , eleRight ) ;
221
- visibleArea . bottom = Math . min ( visibleArea . bottom , eleBottom ) ;
222
- } ) ;
189
+ visibleArea = getVisibleArea ( visibleArea , scrollerList ) ;
223
190
224
191
// Reset back
225
192
popupElement . style . left = originLeft ;
0 commit comments