Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit ab8f0ed

Browse files
authored
Merge pull request #1903 from matrix-org/luke/fix-sticker-picker-position
Quick fix for sticker picker position
2 parents dddd1c4 + e0236c3 commit ab8f0ed

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

src/components/views/rooms/Stickerpicker.js

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,19 @@ export default class Stickerpicker extends React.Component {
127127
}
128128

129129
_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;
134143
}
135144
}
136145

@@ -243,16 +252,33 @@ export default class Stickerpicker extends React.Component {
243252
* @param {Event} e Event that triggered the function
244253
*/
245254
_onShowStickersClick(e) {
255+
// XXX: Simplify by using a context menu that is positioned relative to the sticker picker button
256+
246257
const buttonRect = e.target.getBoundingClientRect();
247258

248259
// 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+
250275
const y = (buttonRect.top + (buttonRect.height / 2) + window.pageYOffset) - 19;
251276

252277
this.setState({
253278
showStickers: true,
254279
stickerPickerX: x,
255280
stickerPickerY: y,
281+
stickerPickerChevronOffset,
256282
});
257283
}
258284

@@ -305,7 +331,7 @@ export default class Stickerpicker extends React.Component {
305331

306332
const stickerPicker = <ContextualMenu
307333
elementClass={GenericElementContextMenu}
308-
chevronOffset={10}
334+
chevronOffset={this.state.stickerPickerChevronOffset}
309335
chevronFace={'bottom'}
310336
left={this.state.stickerPickerX}
311337
top={this.state.stickerPickerY}

0 commit comments

Comments
 (0)