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

mentionSelect (format) can't return HTML #170

Open
kazzkiq opened this issue Sep 16, 2020 · 9 comments
Open

mentionSelect (format) can't return HTML #170

kazzkiq opened this issue Sep 16, 2020 · 9 comments

Comments

@kazzkiq
Copy link

kazzkiq commented Sep 16, 2020

This plugin is awesome and seems to work pretty well already with both <input> elements and also <div contenteditable="true">.

The problem is that even when using this plugin with a <div> (which accepts HTML), I can't format my selection with HTML, because it just writes the HTML as text instead:

example

mentionConfig: MentionConfig = {
  mentionSelect: this.format,
};
//...
format(item: any) {
  return `<span class="chip">${item['name'].split(' ')[0]}</span>`;
}

Is it possible to accept HTML formatting in mentionSelect when using this plugin in contenteditable elements?

@kewur
Copy link

kewur commented Apr 4, 2021

any workarounds for this?

@ashish-chide
Copy link

ashish-chide commented Jun 12, 2021

Facing same issue.

mentionConfig = { items: ['Noah', 'Liam', 'Mason', 'Jacob'], triggerChar: '@', dropUp: true, maxItems: 10, mentionSelect: this.onMentionSelect, };

onMentionSelect(selection): string { return '<b>' + selection.label + '</b>'; }

I am using div with contenteditable but I am not able to style it

@pallaviMN
Copy link

@dmacfarlane @quadsquad1101 @kazzkiq , Did anyone resolve this?

@tenji73
Copy link

tenji73 commented Oct 26, 2021

@dmacfarlane @quadsquad1101 @kazzkiq @pallaviMN

i was facing the same issue and landed here... i ended up with this little hack - its not pretty, but it works...

since the substring may already exist in the string i add some temporary marks to the string like this in the config on select - (no html):
mentionSelect: (e: any) => { return '##' + e.label + '##' }

...and in "itemSelected" after 100ms i search for that string and replace it with html...

itemSelected(event: any) {
		setTimeout(() => {
			this.htmlDoc.innerHTML = this.htmlDoc.innerHTML.replace('##' + event.label + '##', ' <b>' + event.label + '</b> ');
		}, 100);
	}

"this.htmlDoc" is my contenteditable element..

@ThamTran04
Copy link

@tenji73 Hello, do you have the link of Stackblitz for your solution? thanks

@tenji73
Copy link

tenji73 commented Nov 2, 2021

@ThamTran04 sure - here we go:
https://stackblitz.com/edit/angular-ivy-kw3chj

@ThamTran04
Copy link

@ThamTran04 sure - here we go: https://stackblitz.com/edit/angular-ivy-kw3chj

Many thanks again

@iyyappanp786
Copy link

can any one help me that if we type @ or # the seperae dropdown has to be shown only in the div and in angular 15 version

@PierreKabeen
Copy link

Hey for those who are interested, you can also delete a whole mention by simply adding contenteditable="false" to the <b> element provided by @tenji73 :)

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

8 participants