@@ -252,16 +252,33 @@ export default class Stickerpicker extends React.Component {
252
252
* @param {Event } e Event that triggered the function
253
253
*/
254
254
_onShowStickersClick ( e ) {
255
+ // XXX: Simplify by using a context menu that is positioned relative to the sticker picker button
256
+
255
257
const buttonRect = e . target . getBoundingClientRect ( ) ;
256
258
257
259
// The window X and Y offsets are to adjust position when zoomed in to page
258
- const x = buttonRect . right + window . pageXOffset - 42 ;
260
+ let x = buttonRect . right + window . pageXOffset - 41 ;
261
+
262
+ // Amount of horizontal space between the right of menu and the right of the viewport
263
+ // (10 = amount needed to make chevron centrally aligned)
264
+ const rightPad = 10 ;
265
+
266
+ // When the sticker picker would be displayed off of the viewport, adjust x
267
+ // (302 = width of context menu, including borders)
268
+ x = Math . min ( x , document . body . clientWidth - ( 302 + rightPad ) ) ;
269
+
270
+ // Offset the chevron location, which is relative to the left of the context menu
271
+ // (10 = offset when context menu would not be displayed off viewport)
272
+ // (8 = value required in practice (possibly 10 - 2 where the 2 = context menu borders)
273
+ const stickerPickerChevronOffset = Math . max ( 10 , 8 + window . pageXOffset + buttonRect . left - x ) ;
274
+
259
275
const y = ( buttonRect . top + ( buttonRect . height / 2 ) + window . pageYOffset ) - 19 ;
260
276
261
277
this . setState ( {
262
278
showStickers : true ,
263
279
stickerPickerX : x ,
264
280
stickerPickerY : y ,
281
+ stickerPickerChevronOffset,
265
282
} ) ;
266
283
}
267
284
@@ -314,7 +331,7 @@ export default class Stickerpicker extends React.Component {
314
331
315
332
const stickerPicker = < ContextualMenu
316
333
elementClass = { GenericElementContextMenu }
317
- chevronOffset = { 10 }
334
+ chevronOffset = { this . state . stickerPickerChevronOffset }
318
335
chevronFace = { 'bottom' }
319
336
left = { this . state . stickerPickerX }
320
337
top = { this . state . stickerPickerY }
0 commit comments