Skip to content

Commit

Permalink
[Patch] add onClick event listeners for emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jan 27, 2018
1 parent bc78bee commit 39c1b4b
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 77 deletions.
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/universal/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "emoji-picker-react",
"version": "1.7.1",
"version": "1.7.2",
"description": "React emoji-picker component",
"main": "./dist/index.js",
"scripts": {
Expand Down
13 changes: 10 additions & 3 deletions src/DiversityPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ function DiversityPicker({ index, assetPath, emojiResolution, onEmojiClick, clos

let diversities = null;

function onClick(diversity, e) {
function onMouseDown(diversity, e) {
e.preventDefault();
onEmojiClick(diversity, emoji, e);
close();
setTimeout(() => {
close();
}, 500);
}

function onClick(e) {
e.preventDefault();
}

if (emoji && emoji.diversities) {
Expand All @@ -35,7 +41,8 @@ function DiversityPicker({ index, assetPath, emojiResolution, onEmojiClick, clos
key={diversity}
style={style}
className="emoji"
onMouseDown={((e) => onClick(diversity, e))}/>
onClick={onClick}
onMouseDown={((e) => onMouseDown(diversity, e))}/>
);
})
}</div>
Expand Down
9 changes: 7 additions & 2 deletions src/Emoji/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Emoji extends Component {
this.hasDiversities = this.emoji.hasOwnProperty('diversities');

this.onClick = this.onClick.bind(this);
this.emojiChosen = this.emojiChosen.bind(this);
this.onMouseEnter = this.onMouseEnter.bind(this);
this.onMouseLeave = this.onMouseLeave.bind(this);
this.onMouseDown = this.onMouseDown.bind(this);
Expand All @@ -30,10 +31,13 @@ class Emoji extends Component {
}

onClick(e) {
e.preventDefault();
}

emojiChosen(e) {
const { emoji } = this.props;
const onEmojiClick = this.context.onEmojiClick;

e.preventDefault();
onEmojiClick && onEmojiClick(emoji.unified, emoji, e);
}

Expand Down Expand Up @@ -87,7 +91,7 @@ class Emoji extends Component {
delete this.timeCounter;

if (!(counter && (Date.now() - counter) >= OPEN_DIVERSITIES_TIMEOUT)) {
return this.onClick(e);
return this.emojiChosen(e);
}
}

Expand Down Expand Up @@ -115,6 +119,7 @@ class Emoji extends Component {
return (
<a href="#!"
className={className}
onClick={this.onClick}
onMouseEnter={this.onMouseEnter}
onMouseLeave={this.onMouseLeave}
onMouseDown={this.onMouseDown}
Expand Down
4 changes: 3 additions & 1 deletion src/EmojiPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ class EmojiPicker extends Component {

onEmojiClick(unified, emoji, e) {

e.preventDefault();
if (!e.defaultPrevented) {
e.preventDefault();
}

const usedModifiers = modifiers.filter((modifier) => unified.indexOf(modifier) > -1);

Expand Down
Loading

0 comments on commit 39c1b4b

Please sign in to comment.