@@ -57,6 +57,8 @@ type PositionStyle = {
57
57
zIndex ?: '9999' ;
58
58
transition ?: 'none !important' ;
59
59
opacity ?: 0 | 1 ;
60
+ bottom ?: 0 ;
61
+ display ?: 'flex' ;
60
62
} ;
61
63
62
64
type PositionResult = {
@@ -85,7 +87,7 @@ const fallbackOrder = {
85
87
bottom : 'btrl' ,
86
88
right : 'rltb' ,
87
89
left : 'lrbt' ,
88
- } ;
90
+ } as const ;
89
91
90
92
const getParents = function ( element : Element ) : Array < Element | Window > {
91
93
// Set up a parent array
@@ -136,12 +138,14 @@ export const getPositionStyle = ({
136
138
targetBoundaries,
137
139
variantStore,
138
140
target,
141
+ margin = 0 ,
139
142
} : {
140
143
placement : Placements ;
141
144
target : DOMRect ;
142
145
container : DOMRect ;
143
146
targetBoundaries : Boundaries ;
144
147
variantStore ?: VariantBoundaries ;
148
+ margin ?: number ;
145
149
} ) : PositionResult => {
146
150
if ( ! targetBoundaries ) {
147
151
return { } ;
@@ -197,11 +201,11 @@ export const getPositionStyle = ({
197
201
opacity : 1 ,
198
202
} ,
199
203
placement : `${ PlacementMap [ placementAttempt ] } -${ PlacementMap [ v ] } ` ,
200
- } as PositionResult ;
204
+ } as unknown as PositionResult ;
201
205
}
202
206
}
203
207
204
- const placementAttempt = targetBoundaries [ placementAttempts [ 0 ] ] ;
208
+ const placementAttempt = placementAttempts [ 0 ] ;
205
209
206
210
const directionVertical = [ 't' , 'b' ] . includes ( placementAttempt ) ;
207
211
@@ -214,6 +218,10 @@ export const getPositionStyle = ({
214
218
top : `${ point } px` ,
215
219
left : `${ variantPoint } px` ,
216
220
position : 'fixed' ,
221
+ ...( bottom < target . height + point && {
222
+ bottom : margin ,
223
+ display : 'flex' ,
224
+ } ) ,
217
225
zIndex : '9999' ,
218
226
opacity : 1 ,
219
227
} ,
@@ -279,7 +287,7 @@ export const usePosition = (
279
287
} = options ;
280
288
const container = useRef ( containerElement ) ;
281
289
282
- const [ style , setStyle ] = useDebouncedState ( { } as PositionResult , 10 ) ;
290
+ const [ style , setStyle ] = useDebouncedState < PositionResult > ( { } , 10 ) ;
283
291
284
292
const callback = useMutableCallback ( ( ) => {
285
293
const boundaries = target . current . getBoundingClientRect ( ) ;
@@ -299,6 +307,7 @@ export const usePosition = (
299
307
targetBoundaries,
300
308
variantStore,
301
309
target : boundaries ,
310
+ margin,
302
311
} )
303
312
) ;
304
313
} ) ;
0 commit comments