@@ -225,35 +225,57 @@ export default class ContextMenu extends React.PureComponent<IProps, IState> {
225
225
226
226
protected renderMenu ( hasBackground = this . props . hasBackground ) {
227
227
const position : Partial < Writeable < DOMRect > > = { } ;
228
- const props = this . props ;
229
-
230
- if ( props . top ) {
231
- position . top = props . top ;
228
+ const {
229
+ top,
230
+ bottom,
231
+ left,
232
+ right,
233
+ bottomAligned,
234
+ rightAligned,
235
+ menuClassName,
236
+ menuHeight,
237
+ menuWidth,
238
+ menuPaddingLeft,
239
+ menuPaddingRight,
240
+ menuPaddingBottom,
241
+ menuPaddingTop,
242
+ zIndex,
243
+ children,
244
+ focusLock,
245
+ managed,
246
+ wrapperClassName,
247
+ chevronFace : propsChevronFace ,
248
+ chevronOffset : propsChevronOffset ,
249
+ ...props
250
+ } = this . props ;
251
+
252
+ if ( top ) {
253
+ position . top = top ;
232
254
} else {
233
- position . bottom = props . bottom ;
255
+ position . bottom = bottom ;
234
256
}
235
257
236
258
let chevronFace : ChevronFace ;
237
- if ( props . left ) {
238
- position . left = props . left ;
259
+ if ( left ) {
260
+ position . left = left ;
239
261
chevronFace = ChevronFace . Left ;
240
262
} else {
241
- position . right = props . right ;
263
+ position . right = right ;
242
264
chevronFace = ChevronFace . Right ;
243
265
}
244
266
245
267
const contextMenuRect = this . state . contextMenuElem ? this . state . contextMenuElem . getBoundingClientRect ( ) : null ;
246
268
247
269
const chevronOffset : CSSProperties = { } ;
248
- if ( props . chevronFace ) {
249
- chevronFace = props . chevronFace ;
270
+ if ( propsChevronFace ) {
271
+ chevronFace = propsChevronFace ;
250
272
}
251
273
const hasChevron = chevronFace && chevronFace !== ChevronFace . None ;
252
274
253
275
if ( chevronFace === ChevronFace . Top || chevronFace === ChevronFace . Bottom ) {
254
- chevronOffset . left = props . chevronOffset ;
276
+ chevronOffset . left = propsChevronOffset ;
255
277
} else {
256
- chevronOffset . top = props . chevronOffset ;
278
+ chevronOffset . top = propsChevronOffset ;
257
279
}
258
280
259
281
// If we know the dimensions of the context menu, adjust its position to
@@ -262,39 +284,39 @@ export default class ContextMenu extends React.PureComponent<IProps, IState> {
262
284
if ( contextMenuRect ) {
263
285
if ( position . top !== undefined ) {
264
286
let maxTop = windowHeight - WINDOW_PADDING ;
265
- if ( ! this . props . bottomAligned ) {
287
+ if ( ! bottomAligned ) {
266
288
maxTop -= contextMenuRect . height ;
267
289
}
268
290
position . top = Math . min ( position . top , maxTop ) ;
269
291
// Adjust the chevron if necessary
270
292
if ( chevronOffset . top !== undefined ) {
271
- chevronOffset . top = props . chevronOffset + props . top - position . top ;
293
+ chevronOffset . top = propsChevronOffset + top - position . top ;
272
294
}
273
295
} else if ( position . bottom !== undefined ) {
274
296
position . bottom = Math . min (
275
297
position . bottom ,
276
298
windowHeight - contextMenuRect . height - WINDOW_PADDING ,
277
299
) ;
278
300
if ( chevronOffset . top !== undefined ) {
279
- chevronOffset . top = props . chevronOffset + position . bottom - props . bottom ;
301
+ chevronOffset . top = propsChevronOffset + position . bottom - bottom ;
280
302
}
281
303
}
282
304
if ( position . left !== undefined ) {
283
305
let maxLeft = windowWidth - WINDOW_PADDING ;
284
- if ( ! this . props . rightAligned ) {
306
+ if ( ! rightAligned ) {
285
307
maxLeft -= contextMenuRect . width ;
286
308
}
287
309
position . left = Math . min ( position . left , maxLeft ) ;
288
310
if ( chevronOffset . left !== undefined ) {
289
- chevronOffset . left = props . chevronOffset + props . left - position . left ;
311
+ chevronOffset . left = propsChevronOffset + left - position . left ;
290
312
}
291
313
} else if ( position . right !== undefined ) {
292
314
position . right = Math . min (
293
315
position . right ,
294
316
windowWidth - contextMenuRect . width - WINDOW_PADDING ,
295
317
) ;
296
318
if ( chevronOffset . left !== undefined ) {
297
- chevronOffset . left = props . chevronOffset + position . right - props . right ;
319
+ chevronOffset . left = propsChevronOffset + position . right - right ;
298
320
}
299
321
}
300
322
}
@@ -320,36 +342,36 @@ export default class ContextMenu extends React.PureComponent<IProps, IState> {
320
342
'mx_ContextualMenu_withChevron_right' : chevronFace === ChevronFace . Right ,
321
343
'mx_ContextualMenu_withChevron_top' : chevronFace === ChevronFace . Top ,
322
344
'mx_ContextualMenu_withChevron_bottom' : chevronFace === ChevronFace . Bottom ,
323
- 'mx_ContextualMenu_rightAligned' : this . props . rightAligned === true ,
324
- 'mx_ContextualMenu_bottomAligned' : this . props . bottomAligned === true ,
325
- } , this . props . menuClassName ) ;
345
+ 'mx_ContextualMenu_rightAligned' : rightAligned === true ,
346
+ 'mx_ContextualMenu_bottomAligned' : bottomAligned === true ,
347
+ } , menuClassName ) ;
326
348
327
349
const menuStyle : CSSProperties = { } ;
328
- if ( props . menuWidth ) {
329
- menuStyle . width = props . menuWidth ;
350
+ if ( menuWidth ) {
351
+ menuStyle . width = menuWidth ;
330
352
}
331
353
332
- if ( props . menuHeight ) {
333
- menuStyle . height = props . menuHeight ;
354
+ if ( menuHeight ) {
355
+ menuStyle . height = menuHeight ;
334
356
}
335
357
336
- if ( ! isNaN ( Number ( props . menuPaddingTop ) ) ) {
337
- menuStyle [ "paddingTop" ] = props . menuPaddingTop ;
358
+ if ( ! isNaN ( Number ( menuPaddingTop ) ) ) {
359
+ menuStyle [ "paddingTop" ] = menuPaddingTop ;
338
360
}
339
- if ( ! isNaN ( Number ( props . menuPaddingLeft ) ) ) {
340
- menuStyle [ "paddingLeft" ] = props . menuPaddingLeft ;
361
+ if ( ! isNaN ( Number ( menuPaddingLeft ) ) ) {
362
+ menuStyle [ "paddingLeft" ] = menuPaddingLeft ;
341
363
}
342
- if ( ! isNaN ( Number ( props . menuPaddingBottom ) ) ) {
343
- menuStyle [ "paddingBottom" ] = props . menuPaddingBottom ;
364
+ if ( ! isNaN ( Number ( menuPaddingBottom ) ) ) {
365
+ menuStyle [ "paddingBottom" ] = menuPaddingBottom ;
344
366
}
345
- if ( ! isNaN ( Number ( props . menuPaddingRight ) ) ) {
346
- menuStyle [ "paddingRight" ] = props . menuPaddingRight ;
367
+ if ( ! isNaN ( Number ( menuPaddingRight ) ) ) {
368
+ menuStyle [ "paddingRight" ] = menuPaddingRight ;
347
369
}
348
370
349
371
const wrapperStyle = { } ;
350
- if ( ! isNaN ( Number ( props . zIndex ) ) ) {
351
- menuStyle [ "zIndex" ] = props . zIndex + 1 ;
352
- wrapperStyle [ "zIndex" ] = props . zIndex ;
372
+ if ( ! isNaN ( Number ( zIndex ) ) ) {
373
+ menuStyle [ "zIndex" ] = zIndex + 1 ;
374
+ wrapperStyle [ "zIndex" ] = zIndex ;
353
375
}
354
376
355
377
let background ;
@@ -366,10 +388,10 @@ export default class ContextMenu extends React.PureComponent<IProps, IState> {
366
388
367
389
let body = < >
368
390
{ chevron }
369
- { props . children }
391
+ { children }
370
392
</ > ;
371
393
372
- if ( props . focusLock ) {
394
+ if ( focusLock ) {
373
395
body = < FocusLock >
374
396
{ body }
375
397
</ FocusLock > ;
@@ -379,7 +401,7 @@ export default class ContextMenu extends React.PureComponent<IProps, IState> {
379
401
< RovingTabIndexProvider handleHomeEnd handleUpDown onKeyDown = { this . onKeyDown } >
380
402
{ ( { onKeyDownHandler } ) => (
381
403
< div
382
- className = { classNames ( "mx_ContextualMenu_wrapper" , this . props . wrapperClassName ) }
404
+ className = { classNames ( "mx_ContextualMenu_wrapper" , wrapperClassName ) }
383
405
style = { { ...position , ...wrapperStyle } }
384
406
onClick = { this . onClick }
385
407
onKeyDown = { onKeyDownHandler }
@@ -390,7 +412,8 @@ export default class ContextMenu extends React.PureComponent<IProps, IState> {
390
412
className = { menuClasses }
391
413
style = { menuStyle }
392
414
ref = { this . collectContextMenuRect }
393
- role = { this . props . managed ? "menu" : undefined }
415
+ role = { managed ? "menu" : undefined }
416
+ { ...props }
394
417
>
395
418
{ body }
396
419
</ div >
0 commit comments