Skip to content

Commit

Permalink
[MM-26673] Attach emoji picker to the Post Edit Modal (mattermost#5869
Browse files Browse the repository at this point in the history
)

Co-authored-by: Mattermod <[email protected]>
  • Loading branch information
jfrerich and mattermod committed Jul 29, 2020
1 parent e84b768 commit 5354903
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ exports[`components/EditPostModal should disable the button on not canDeletePost
onEmojiClick={[Function]}
onGifClick={[Function]}
onHide={[Function]}
rightOffset={10}
show={false}
spaceRequiredAbove={476}
spaceRequiredBelow={497}
target={[Function]}
topOffset={-20}
topOffset={0}
/>
<button
aria-label="emoji picker"
Expand Down Expand Up @@ -256,11 +257,12 @@ exports[`components/EditPostModal should disable the button on not canEditPost a
onEmojiClick={[Function]}
onGifClick={[Function]}
onHide={[Function]}
rightOffset={10}
show={false}
spaceRequiredAbove={476}
spaceRequiredBelow={497}
target={[Function]}
topOffset={-20}
topOffset={0}
/>
<button
aria-label="emoji picker"
Expand Down Expand Up @@ -417,11 +419,12 @@ exports[`components/EditPostModal should match snapshot with useChannelMentions
onEmojiClick={[Function]}
onGifClick={[Function]}
onHide={[Function]}
rightOffset={10}
show={false}
spaceRequiredAbove={476}
spaceRequiredBelow={497}
target={[Function]}
topOffset={-20}
topOffset={0}
/>
<button
aria-label="emoji picker"
Expand Down Expand Up @@ -578,11 +581,12 @@ exports[`components/EditPostModal should match with default config 1`] = `
onEmojiClick={[Function]}
onGifClick={[Function]}
onHide={[Function]}
rightOffset={10}
show={false}
spaceRequiredAbove={476}
spaceRequiredBelow={497}
target={[Function]}
topOffset={-20}
topOffset={0}
/>
<button
aria-label="emoji picker"
Expand Down Expand Up @@ -875,11 +879,12 @@ exports[`components/EditPostModal should not disable the button on not canDelete
onEmojiClick={[Function]}
onGifClick={[Function]}
onHide={[Function]}
rightOffset={10}
show={false}
spaceRequiredAbove={476}
spaceRequiredBelow={497}
target={[Function]}
topOffset={-20}
topOffset={0}
/>
<button
aria-label="emoji picker"
Expand Down Expand Up @@ -1036,11 +1041,12 @@ exports[`components/EditPostModal should not disable the button on not canEditPo
onEmojiClick={[Function]}
onGifClick={[Function]}
onHide={[Function]}
rightOffset={10}
show={false}
spaceRequiredAbove={476}
spaceRequiredBelow={497}
target={[Function]}
topOffset={-20}
topOffset={0}
/>
<button
aria-label="emoji picker"
Expand Down Expand Up @@ -1197,11 +1203,12 @@ exports[`components/EditPostModal should not disable the save button on not canD
onEmojiClick={[Function]}
onGifClick={[Function]}
onHide={[Function]}
rightOffset={10}
show={false}
spaceRequiredAbove={476}
spaceRequiredBelow={497}
target={[Function]}
topOffset={-20}
topOffset={0}
/>
<button
aria-label="emoji picker"
Expand Down Expand Up @@ -1358,11 +1365,12 @@ exports[`components/EditPostModal should show emojis on emojis click 1`] = `
onEmojiClick={[Function]}
onGifClick={[Function]}
onHide={[Function]}
rightOffset={10}
show={true}
spaceRequiredAbove={476}
spaceRequiredBelow={497}
target={[Function]}
topOffset={-20}
topOffset={0}
/>
<button
aria-label="emoji picker"
Expand Down Expand Up @@ -1519,11 +1527,12 @@ exports[`components/EditPostModal should show errors when it is set in the state
onEmojiClick={[Function]}
onGifClick={[Function]}
onHide={[Function]}
rightOffset={10}
show={false}
spaceRequiredAbove={476}
spaceRequiredBelow={497}
target={[Function]}
topOffset={-20}
topOffset={0}
/>
<button
aria-label="emoji picker"
Expand Down
9 changes: 6 additions & 3 deletions components/edit_post_modal/edit_post_modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import Textbox from 'components/textbox';
import TextboxLinks from 'components/textbox/textbox_links';

const KeyCodes = Constants.KeyCodes;
const TOP_OFFSET = 0;
const RIGHT_OFFSET = 10;

class EditPostModal extends React.PureComponent {
static propTypes = {
Expand Down Expand Up @@ -155,7 +157,7 @@ class EditPostModal extends React.PureComponent {
this.editbox.focus();
}

getEditPostControls = () => {
getTarget = () => {
return this.refs.editPostEmoji;
}

Expand Down Expand Up @@ -375,12 +377,13 @@ class EditPostModal extends React.PureComponent {
<EmojiPickerOverlay
show={this.state.showEmojiPicker}
container={this.getContainer}
target={this.getEditPostControls}
target={this.getTarget}
onHide={this.hideEmojiPicker}
onEmojiClick={this.handleEmojiClick}
onGifClick={this.handleGifClick}
enableGifPicker={this.props.config.EnableGifPicker === 'true'}
topOffset={-20}
topOffset={TOP_OFFSET}
rightOffset={RIGHT_OFFSET}
/>
<button
aria-label={emojiButtonAriaLabel}
Expand Down
6 changes: 6 additions & 0 deletions components/emoji_picker/emoji_picker_overlay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class EmojiPickerOverlay extends React.PureComponent {
onGifClick: PropTypes.func,
onHide: PropTypes.func.isRequired,
topOffset: PropTypes.number,
rightOffset: PropTypes.number,
spaceRequiredAbove: PropTypes.number,
spaceRequiredBelow: PropTypes.number,
enableGifPicker: PropTypes.bool,
Expand All @@ -48,6 +49,11 @@ export default class EmojiPickerOverlay extends React.PureComponent {

static emojiPickerPosition(props) {
const emojiTrigger = props.target();

if (typeof props.rightOffset !== 'undefined') {
return props.rightOffset;
}

let rightOffset = Constants.DEFAULT_EMOJI_PICKER_RIGHT_OFFSET;
if (emojiTrigger) {
rightOffset = window.innerWidth - emojiTrigger.getBoundingClientRect().left - Constants.DEFAULT_EMOJI_PICKER_LEFT_OFFSET;
Expand Down

0 comments on commit 5354903

Please sign in to comment.