@@ -41,6 +41,9 @@ class Modal extends Component {
41
41
/** A modal can reduce its complexity */
42
42
basic : PropTypes . bool ,
43
43
44
+ /** A modal can be vertically centered in the viewport */
45
+ centered : PropTypes . bool ,
46
+
44
47
/** Primary content. */
45
48
children : PropTypes . node ,
46
49
@@ -140,6 +143,7 @@ class Modal extends Component {
140
143
}
141
144
142
145
static defaultProps = {
146
+ centered : true ,
143
147
dimmer : true ,
144
148
closeOnDimmerClick : true ,
145
149
closeOnDocumentClick : false ,
@@ -216,6 +220,18 @@ class Modal extends Component {
216
220
217
221
handleRef = c => ( this . ref = c )
218
222
223
+ handlePortalRef = c => ( this . portalRef = c )
224
+
225
+ setRootNodeStyle = ( ) => {
226
+ debug ( 'setRootNodeStyle()' )
227
+
228
+ if ( ! this . portalRef ) return
229
+
230
+ if ( this . portalRef ) {
231
+ this . portalRef . rootNode . style . setProperty ( 'display' , 'flex' , 'important' )
232
+ }
233
+ }
234
+
219
235
setPositionAndClassNames = ( ) => {
220
236
const { dimmer } = this . props
221
237
let classes
@@ -233,7 +249,10 @@ class Modal extends Component {
233
249
if ( this . ref ) {
234
250
const { height } = this . ref . getBoundingClientRect ( )
235
251
236
- const marginTop = - Math . round ( height / 2 )
252
+ // Leaving the old calculation here since we may need it as an older browser fallback
253
+ // SEE: https://github.com/Semantic-Org/Semantic-UI/issues/6185#issuecomment-376725956
254
+ // const marginTop = -Math.round(height / 2)
255
+ const marginTop = null
237
256
const scrolling = height >= window . innerHeight
238
257
239
258
if ( this . state . marginTop !== marginTop ) {
@@ -251,6 +270,8 @@ class Modal extends Component {
251
270
if ( ! _ . isEmpty ( newState ) ) this . setState ( newState )
252
271
253
272
this . animationRequestId = requestAnimationFrame ( this . setPositionAndClassNames )
273
+
274
+ this . setRootNodeStyle ( )
254
275
}
255
276
256
277
renderContent = ( rest ) => {
@@ -312,7 +333,7 @@ class Modal extends Component {
312
333
313
334
render ( ) {
314
335
const { open } = this . state
315
- const { closeOnDimmerClick, closeOnDocumentClick, dimmer, eventPool, trigger } = this . props
336
+ const { centered , closeOnDimmerClick, closeOnDocumentClick, dimmer, eventPool, trigger } = this . props
316
337
const mountNode = this . getMountNode ( )
317
338
318
339
// Short circuit when server side rendering
@@ -336,6 +357,7 @@ class Modal extends Component {
336
357
: cx (
337
358
'ui' ,
338
359
dimmer === 'inverted' && 'inverted' ,
360
+ ! centered && 'top aligned' ,
339
361
'page modals dimmer transition visible active' ,
340
362
)
341
363
@@ -364,6 +386,7 @@ class Modal extends Component {
364
386
onMount = { this . handlePortalMount }
365
387
onOpen = { this . handleOpen }
366
388
onUnmount = { this . handlePortalUnmount }
389
+ ref = { this . handlePortalRef }
367
390
>
368
391
{ this . renderContent ( rest ) }
369
392
</ Portal >
0 commit comments