Skip to content

Commit

Permalink
[FIX] EmojiPicker position on small screens (#12457)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramrami authored and ggazzo committed Oct 29, 2018
1 parent 773c387 commit 20c8222
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/rocketchat-emoji/client/lib/EmojiPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,23 @@ RocketChat.EmojiPicker = {
},
setPosition() {
const windowHeight = window.innerHeight;
const windowWidth = window.innerWidth;
const windowBorder = 10;
const sourcePos = $(this.source).offset();
const { left, top } = sourcePos;
const cssProperties = { top, left };
const isLargerThanWindow = this.width + windowBorder > windowWidth;

if (top + this.height >= windowHeight) {
cssProperties.top = windowHeight - this.height - windowBorder;
}

if (left < windowBorder) {
cssProperties.left = windowBorder;
cssProperties.left = isLargerThanWindow ? 0 : windowBorder;
}

if (left + this.width >= window.innerWidth) {
cssProperties.left = left - this.width - windowBorder;
if (left + this.width >= windowWidth) {
cssProperties.left = isLargerThanWindow ? 0 : windowWidth - this.width - windowBorder;
}

return $('.emoji-picker').css(cssProperties);
Expand Down

0 comments on commit 20c8222

Please sign in to comment.