@@ -4,6 +4,7 @@ import _ from 'lodash'
4
4
import PropTypes from 'prop-types'
5
5
import React , { Component , createRef } from 'react'
6
6
import { Popper } from 'react-popper'
7
+ import shallowEqual from 'shallowequal'
7
8
8
9
import {
9
10
eventStack ,
@@ -126,6 +127,9 @@ export default class Popup extends Component {
126
127
/** An object containing custom settings for the Popper.js modifiers. */
127
128
popperModifiers : PropTypes . object ,
128
129
130
+ /** A popup can have dependencies which update will schedule a position update. */
131
+ popperDependencies : PropTypes . array ,
132
+
129
133
/** Popup size. */
130
134
size : PropTypes . oneOf ( _ . without ( SUI . SIZES , 'medium' , 'big' , 'massive' ) ) ,
131
135
@@ -151,6 +155,8 @@ export default class Popup extends Component {
151
155
static Header = PopupHeader
152
156
153
157
state = { }
158
+
159
+ open = false
154
160
triggerRef = createRef ( )
155
161
156
162
static getDerivedStateFromProps ( props , state ) {
@@ -171,6 +177,14 @@ export default class Popup extends Component {
171
177
return { contentRestProps, portalRestProps }
172
178
}
173
179
180
+ componentDidUpdate ( prevProps ) {
181
+ const depsEqual = shallowEqual ( this . props . popperDependencies , prevProps . popperDependencies )
182
+
183
+ if ( ! depsEqual ) {
184
+ this . handleUpdate ( )
185
+ }
186
+ }
187
+
174
188
componentWillUnmount ( ) {
175
189
clearTimeout ( this . timeoutId )
176
190
}
@@ -235,10 +249,21 @@ export default class Popup extends Component {
235
249
236
250
handlePortalUnmount = ( e ) => {
237
251
debug ( 'handlePortalUnmount()' )
252
+
253
+ this . positionUpdate = null
238
254
_ . invoke ( this . props , 'onUnmount' , e , this . props )
239
255
}
240
256
241
- renderContent = ( { placement : popperPlacement , ref : popperRef , style : popperStyle } ) => {
257
+ handleUpdate ( ) {
258
+ if ( this . positionUpdate ) this . positionUpdate ( )
259
+ }
260
+
261
+ renderContent = ( {
262
+ placement : popperPlacement ,
263
+ ref : popperRef ,
264
+ scheduleUpdate,
265
+ style : popperStyle ,
266
+ } ) => {
242
267
const {
243
268
basic,
244
269
children,
@@ -254,6 +279,8 @@ export default class Popup extends Component {
254
279
} = this . props
255
280
const { contentRestProps } = this . state
256
281
282
+ this . positionUpdate = scheduleUpdate
283
+
257
284
const classes = cx (
258
285
'ui' ,
259
286
placementMapping [ popperPlacement ] ,
0 commit comments