@@ -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
@@ -243,16 +252,33 @@ export default class Stickerpicker extends React.Component {
243
252
* @param {Event } e Event that triggered the function
244
253
*/
245
254
_onShowStickersClick ( e ) {
255
+ // XXX: Simplify by using a context menu that is positioned relative to the sticker picker button
256
+
246
257
const buttonRect = e . target . getBoundingClientRect ( ) ;
247
258
248
259
// The window X and Y offsets are to adjust position when zoomed in to page
249
- 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
+
250
275
const y = ( buttonRect . top + ( buttonRect . height / 2 ) + window . pageYOffset ) - 19 ;
251
276
252
277
this . setState ( {
253
278
showStickers : true ,
254
279
stickerPickerX : x ,
255
280
stickerPickerY : y ,
281
+ stickerPickerChevronOffset,
256
282
} ) ;
257
283
}
258
284
@@ -305,7 +331,7 @@ export default class Stickerpicker extends React.Component {
305
331
306
332
const stickerPicker = < ContextualMenu
307
333
elementClass = { GenericElementContextMenu }
308
- chevronOffset = { 10 }
334
+ chevronOffset = { this . state . stickerPickerChevronOffset }
309
335
chevronFace = { 'bottom' }
310
336
left = { this . state . stickerPickerX }
311
337
top = { this . state . stickerPickerY }
0 commit comments