Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contenteditable property for Emoji component #169

Closed
kafeltz opened this issue Feb 27, 2018 · 2 comments
Closed

Add contenteditable property for Emoji component #169

kafeltz opened this issue Feb 27, 2018 · 2 comments

Comments

@kafeltz
Copy link

kafeltz commented Feb 27, 2018

This works as expected:

<span dangerouslySetInnerHTML={{
  __html: Emoji({
    html: true
    set: 'apple'
    emoji: '+1'
    size: 24
  })
}}></span>

But I'm using the generated code inside a <div contenteditable="true"> and the caret enters inside de <span ... > instead jumping the emote icon.

What happens is this:
<span style="..." class="emoji-mart-emoji">CARRET ENTERS HERE AND ADD TYPED TEXT</span>

The solution to fix this is simple. The <span> generated with the attribute html: true needs to output <span style="..." class="emoji-mart-emoji" CONTENTEDITABLE="FALSE">. Maybe this should be optional.

@kafeltz
Copy link
Author

kafeltz commented Feb 27, 2018

I forgot to mention that my workaround at the moment to inject this property was this:

const emojiCreator = tag => {
    return Emoji({ emoji: tag, html: true, size: 16, fallback: emoji => `:${emoji.short_names[0]}:` }).replace(/>/, ' contenteditable="false">')
}

@EtienneLem
Copy link
Member

👋

I was actually implementing that as you suggested, but I realized that it could leave an empty <span> (the one that has dangerouslySetInnerHTML in your example) and it could be bugish when typing in that span or trying to remove it. Not that I mind adding contenteditable=false, but the bulletproof way to fix your issue would be to add contentEditable={false} to your span with dangerouslySetInnerHTML

<span contentEditable={false} dangerouslySetInnerHTML={{
  __html: Emoji({
    html: true
    set: 'apple'
    emoji: '+1'
    size: 24
  })
}}></span>

Then the <span class="emoji-mart-emoji"> inside won’t be editable. I added a section in the README, thanks for pointing that out! 🤘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants