@@ -36,11 +36,11 @@ import {computePosition, size} from '@floating-ui/dom';
36
36
computePosition (referenceEl, floatingEl, {
37
37
middleware: [
38
38
size ({
39
- apply ({width, height, reference, floating }) {
39
+ apply ({availableWidth, availableHeight, elements }) {
40
40
// Do things with the data, e.g.
41
- Object .assign (floatingEl .style , {
42
- maxWidth: ` ${ width } px` ,
43
- maxHeight: ` ${ height } px` ,
41
+ Object .assign (elements . floating .style , {
42
+ maxWidth: ` ${ availableWidth } px` ,
43
+ maxHeight: ` ${ availableHeight } px` ,
44
44
});
45
45
},
46
46
}),
@@ -57,7 +57,12 @@ These are the options you can pass to `size(){:js}`.
57
57
58
58
``` ts
59
59
interface Options extends DetectOverflowOptions {
60
- apply? : (args : Dimensions & ElementRects ) => void ;
60
+ apply? : (
61
+ args : MiddlewareArguments & {
62
+ availableWidth: number ;
63
+ availableHeight: number ;
64
+ }
65
+ ) => void ;
61
66
}
62
67
```
63
68
@@ -72,16 +77,36 @@ lifecycle:
72
77
73
78
``` js
74
79
size ({
75
- apply ({width, height}) {
80
+ apply ({
81
+ availableWidth,
82
+ availableHeight,
83
+ ... middlewareArguments
84
+ }) {
76
85
// Style mutations here
77
86
},
78
87
});
79
88
```
80
89
81
- This is because the ` x ` and ` y ` coordinates become incorrect
82
- after you've changed the size, and so changes to the dimensions
83
- of the floating element need to be performed before the
84
- coordinates get assigned to it.
90
+ #### availableWidth
91
+
92
+ Represents how wide the floating element can be before it will
93
+ overflow its clipping context. You'll generally set this as the
94
+ ` maxWidth{:.objectKey} ` CSS property.
95
+
96
+ #### availableHeight
97
+
98
+ Represents how tall the floating element can be before it will
99
+ overflow its clipping context. You'll generally set this as the
100
+ ` maxHeight{:.objectKey} ` CSS property.
101
+
102
+ #### ...middlewareArguments
103
+
104
+ See [ MiddlewareArguments] ( /docs/middleware#middlewarearguments ) .
105
+
106
+ Many useful properties are also accessible via this callback,
107
+ such as ` rects{:.objectKey} ` and ` elements{:.objectKey} ` , the
108
+ latter of which is useful in the context of React where you need
109
+ access to the floating element and it does not exist in scope.
85
110
86
111
### ...detectOverflowOptions
87
112
@@ -113,7 +138,7 @@ placement is used. In this scenario, place `size(){:js}`
113
138
const middleware = [
114
139
flip (),
115
140
size ({
116
- apply ({width, height }) {
141
+ apply ({availableWidth, availableHeight }) {
117
142
// ...
118
143
},
119
144
}),
@@ -155,11 +180,11 @@ and are setting a minimum acceptable size, place `size(){:js}`
155
180
``` js
156
181
const middleware = [
157
182
size ({
158
- apply ({width, height }) {
159
- Object .assign (floatingEl .style , {
183
+ apply ({availableHeight, elements }) {
184
+ Object .assign (elements . floating .style , {
160
185
// Minimum acceptable height is 50px.
161
186
// `flip` will then take over.
162
- maxHeight: ` ${ Math .max (50 , height )} px` ,
187
+ maxHeight: ` ${ Math .max (50 , availableHeight )} px` ,
163
188
});
164
189
},
165
190
}),
@@ -176,11 +201,11 @@ the width of the reference regardless of its contents. You can
176
201
also use ` size(){:js} ` for this, as the ` Rect{:.class} ` s get
177
202
passed in:
178
203
179
- ``` js
204
+ ``` js /rects/
180
205
size ({
181
- apply ({reference }) {
206
+ apply ({rects }) {
182
207
Object .assign (floatingEl .style , {
183
- width: ` ${ reference .width } px` ,
208
+ width: ` ${ rects . reference .width } px` ,
184
209
});
185
210
},
186
211
});
0 commit comments