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

Commit e0236c3

Browse files
committed
Fix issue with sticker picker rendering off-screen
when the RightPanel is collapsed on a small monitor and the sticker picker is opened.
1 parent 3761cd4 commit e0236c3

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/components/views/rooms/Stickerpicker.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,33 @@ export default class Stickerpicker extends React.Component {
252252
* @param {Event} e Event that triggered the function
253253
*/
254254
_onShowStickersClick(e) {
255+
// XXX: Simplify by using a context menu that is positioned relative to the sticker picker button
256+
255257
const buttonRect = e.target.getBoundingClientRect();
256258

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

261277
this.setState({
262278
showStickers: true,
263279
stickerPickerX: x,
264280
stickerPickerY: y,
281+
stickerPickerChevronOffset,
265282
});
266283
}
267284

@@ -314,7 +331,7 @@ export default class Stickerpicker extends React.Component {
314331

315332
const stickerPicker = <ContextualMenu
316333
elementClass={GenericElementContextMenu}
317-
chevronOffset={10}
334+
chevronOffset={this.state.stickerPickerChevronOffset}
318335
chevronFace={'bottom'}
319336
left={this.state.stickerPickerX}
320337
top={this.state.stickerPickerY}

0 commit comments

Comments
 (0)