@@ -99,77 +99,75 @@ function floatingUi(
99
99
) ;
100
100
}
101
101
102
- const update = async ( ) => {
103
- const { x, y, placement, middlewareData } = await computePosition (
104
- referenceElement ,
105
- floatingElement ,
106
- {
107
- middleware,
108
- placement : defaultPlacement ,
109
- } ,
110
- ) ;
111
-
112
- Object . assign ( floatingElement . style , {
113
- transform : `translate3d(${ Math . round ( x ) } px, ${ Math . round ( y ) } px, 0)` ,
114
- visibility : middlewareData . hide ?. referenceHidden ? 'hidden' : 'visible' ,
115
- } ) ;
116
-
117
- if ( middlewareData . arrow ) {
118
- const { x } = middlewareData . arrow ;
119
- const [ side , alignment ] = placement . split ( '-' ) as [
120
- 'top' | 'bottom' ,
121
- 'string' | undefined ,
122
- ] ;
123
- const isAligned = alignment != null ;
124
-
125
- const unsetSides = {
126
- top : '' ,
127
- bottom : '' ,
128
- left : '' ,
129
- right : '' ,
130
- } ;
131
-
132
- const rotation = {
133
- top : '180deg' ,
134
- bottom : '0deg' ,
135
- } [ side ] ;
136
-
137
- Object . assign ( arrowElement ! . style , {
138
- ...unsetSides ,
139
- transform : `rotate(${ rotation } )` ,
102
+ const update = ( ) => {
103
+ void computePosition ( referenceElement , floatingElement , {
104
+ middleware,
105
+ placement : defaultPlacement ,
106
+ } ) . then ( ( { x, y, placement, middlewareData } ) => {
107
+ Object . assign ( floatingElement . style , {
108
+ transform : `translate3d(${ Math . round ( x ) } px, ${ Math . round ( y ) } px, 0)` ,
109
+ visibility : middlewareData . hide ?. referenceHidden ? 'hidden' : 'visible' ,
140
110
} ) ;
141
111
142
- if ( isAligned ) {
143
- const crossSide = {
144
- 'top-start' : 'left' ,
145
- 'top-end' : 'right' ,
146
- 'bottom-start' : 'left' ,
147
- 'bottom-end' : 'right' ,
148
- } [ placement as 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' ] ;
112
+ if ( middlewareData . arrow ) {
113
+ const { x } = middlewareData . arrow ;
114
+ const [ side , alignment ] = placement . split ( '-' ) as [
115
+ 'top' | 'bottom' ,
116
+ 'string' | undefined ,
117
+ ] ;
118
+ const isAligned = alignment != null ;
119
+
120
+ const unsetSides = {
121
+ top : '' ,
122
+ bottom : '' ,
123
+ left : '' ,
124
+ right : '' ,
125
+ } ;
126
+
127
+ const rotation = {
128
+ top : '180deg' ,
129
+ bottom : '0deg' ,
130
+ } [ side ] ;
149
131
150
132
Object . assign ( arrowElement ! . style , {
151
- [ crossSide ] :
152
- typeof options . arrow ?. position === 'string'
153
- ? options . arrow . position
154
- : `${ options . arrow ?. position } px` ,
155
- } ) ;
156
- } else {
157
- Object . assign ( arrowElement ! . style , {
158
- left : x != null ? `${ x } px` : '' ,
133
+ ...unsetSides ,
134
+ transform : `rotate(${ rotation } )` ,
159
135
} ) ;
160
- }
161
-
162
- const mainSide = {
163
- top : 'bottom' ,
164
- bottom : 'top' ,
165
- } [ side ] ;
166
136
167
- if ( options . arrow ?. offset ) {
168
- Object . assign ( arrowElement ! . style , {
169
- [ mainSide ] : `${ - options . arrow ?. offset } px` ,
170
- } ) ;
137
+ if ( isAligned ) {
138
+ const crossSide = {
139
+ 'top-start' : 'left' ,
140
+ 'top-end' : 'right' ,
141
+ 'bottom-start' : 'left' ,
142
+ 'bottom-end' : 'right' ,
143
+ } [
144
+ placement as 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end'
145
+ ] ;
146
+
147
+ Object . assign ( arrowElement ! . style , {
148
+ [ crossSide ] :
149
+ typeof options . arrow ?. position === 'string'
150
+ ? options . arrow . position
151
+ : `${ options . arrow ?. position } px` ,
152
+ } ) ;
153
+ } else {
154
+ Object . assign ( arrowElement ! . style , {
155
+ left : x != null ? `${ x } px` : '' ,
156
+ } ) ;
157
+ }
158
+
159
+ const mainSide = {
160
+ top : 'bottom' ,
161
+ bottom : 'top' ,
162
+ } [ side ] ;
163
+
164
+ if ( options . arrow ?. offset ) {
165
+ Object . assign ( arrowElement ! . style , {
166
+ [ mainSide ] : `${ - options . arrow ?. offset } px` ,
167
+ } ) ;
168
+ }
171
169
}
172
- }
170
+ } ) ;
173
171
} ;
174
172
175
173
const cleanup = autoUpdate ( referenceElement , floatingElement , update ) ;
0 commit comments