Tippyjs: Line break in functionality in tippy

Created on 15 Sep 2018  路  7Comments  路  Source: atomiks/tippyjs

When the title message is need to show with bullets.
Then I want show tooltip message containing line break
I tried with \n
also tried "&#013";
But line break didnt work in tippy

Most helpful comment

@Slapbox

Can use fragments and <br /> element

<Tippy content={
  <>
    line 1
    <br />
    line 2
  </>
}>
  <button />
</Tippy>

All 7 comments

Why not:

<ul>
  <li>...</li>
  <li>...</li>
</ul>

Using a HTML template would be easier

You can use <br> as title can contain HTML

This doesn't work for me in the React version. Am I doing something wrong there?

@Slapbox

Can use fragments and <br /> element

<Tippy content={
  <>
    line 1
    <br />
    line 2
  </>
}>
  <button />
</Tippy>

Thank you @atomiks!

It would be nice if this was native to tippy, I don't see why \n isn't displayed properly. I do not want to use HTML in tippy because of potential XSS, and escaping it all in JavaScript seems like a lot of wasted effort.

Not everyone uses React.

Here's a workaround:

.tippy-content {
    white-space: pre-line;
}

I mean the library just uses .textContent to set content by default, which doesn't wrap newlines, and the CSS just uses browser defaults. So that's just a solution rather than a workaround.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

skazhikadyadya picture skazhikadyadya  路  3Comments

andrewckor picture andrewckor  路  4Comments

Kearsan picture Kearsan  路  3Comments

khanamiryan picture khanamiryan  路  5Comments

KubaJastrz picture KubaJastrz  路  3Comments