Skip to content

How to prevent quill mention triggering "Enter" on keyDown event handler? #295

Answered by hieutadev
jaypeetancero asked this question in Q&A
Discussion options

You must be logged in to vote

This is how I handle it:

const Mention = Quill.import('modules/mention');
class CustomMention extends Mention {
  hideMentionList() {
    this.options.onBeforeClose();
    this.mentionContainer.style.display = 'none';
    this.mentionContainer.remove();
    this.quill.root.removeAttribute('aria-activedescendant');
    setTimeout(() => this.setIsOpen(false), 0);
  }
}
Quill.register('modules/mention', CustomMention, true);
const handleKeyDown = (e: React.KeyboardEvent) => {
  if (e.key === 'Enter' && !e.shiftKey && ref.current) {
    const editor = ref.current.getEditor();
    const isOpenMention = Boolean(editor.getModule('mention')?.isOpen);
    if (isOpenMention) return;
    // do somet…

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@rushi-visilean
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by csculley
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants
Converted from issue

This discussion was converted from issue #172 on July 16, 2023 08:25.