@@ -127,10 +127,19 @@ export default class Stickerpicker extends React.Component {
127
127
}
128
128
129
129
_onWidgetAction ( payload ) {
130
- if ( payload . action === "user_widget_updated" ) {
131
- this . forceUpdate ( ) ;
132
- } else if ( payload . action === "stickerpicker_close" ) {
133
- this . setState ( { showStickers : false } ) ;
130
+ switch ( payload . action ) {
131
+ case "user_widget_updated" :
132
+ this . forceUpdate ( ) ;
133
+ break ;
134
+ case "stickerpicker_close" :
135
+ this . setState ( { showStickers : false } ) ;
136
+ break ;
137
+ case "show_right_panel" :
138
+ case "hide_right_panel" :
139
+ case "show_left_panel" :
140
+ case "hide_left_panel" :
141
+ this . setState ( { showStickers : false } ) ;
142
+ break ;
134
143
}
135
144
}
136
145
@@ -244,16 +253,33 @@ export default class Stickerpicker extends React.Component {
244
253
* @param {Event } e Event that triggered the function
245
254
*/
246
255
_onShowStickersClick ( e ) {
256
+ // XXX: Simplify by using a context menu that is positioned relative to the sticker picker button
257
+
247
258
const buttonRect = e . target . getBoundingClientRect ( ) ;
248
259
249
260
// The window X and Y offsets are to adjust position when zoomed in to page
250
- const x = buttonRect . right + window . pageXOffset - 42 ;
261
+ let x = buttonRect . right + window . pageXOffset - 41 ;
262
+
263
+ // Amount of horizontal space between the right of menu and the right of the viewport
264
+ // (10 = amount needed to make chevron centrally aligned)
265
+ const rightPad = 10 ;
266
+
267
+ // When the sticker picker would be displayed off of the viewport, adjust x
268
+ // (302 = width of context menu, including borders)
269
+ x = Math . min ( x , document . body . clientWidth - ( 302 + rightPad ) ) ;
270
+
271
+ // Offset the chevron location, which is relative to the left of the context menu
272
+ // (10 = offset when context menu would not be displayed off viewport)
273
+ // (8 = value required in practice (possibly 10 - 2 where the 2 = context menu borders)
274
+ const stickerPickerChevronOffset = Math . max ( 10 , 8 + window . pageXOffset + buttonRect . left - x ) ;
275
+
251
276
const y = ( buttonRect . top + ( buttonRect . height / 2 ) + window . pageYOffset ) - 19 ;
252
277
253
278
this . setState ( {
254
279
showStickers : true ,
255
280
stickerPickerX : x ,
256
281
stickerPickerY : y ,
282
+ stickerPickerChevronOffset,
257
283
} ) ;
258
284
}
259
285
@@ -306,7 +332,7 @@ export default class Stickerpicker extends React.Component {
306
332
307
333
const stickerPicker = < ContextualMenu
308
334
elementClass = { GenericElementContextMenu }
309
- chevronOffset = { 10 }
335
+ chevronOffset = { this . state . stickerPickerChevronOffset }
310
336
chevronFace = { 'bottom' }
311
337
left = { this . state . stickerPickerX }
312
338
top = { this . state . stickerPickerY }
0 commit comments