1

Please guide how to add line break in MudToolTip text. I have a string variable toolTipText in my MudBlazor application. This variable is used as Text in MudTooltip. I want adding System.Environment.NewLine as two lines separator, but it does not effect and tooltip shows only one line. My code is as below:

Sample Code

"Line 1 text" and "Line 2 text" are shown together on one line.

Shakil Ahmed
  • 107
  • 1
  • 7

2 Answers2

1

Instead of providing a string as text, you can also embed HTML in your tooltip:

<MudTooltip>
    <ChildContent>
        <MudIconButton Icon="@Icons.Filled.Info" />
    </ChildContent>
    <TooltipContent>
        <MudText Typo="Typo.body2">Line 1 text</MudText>
        <MudText Typo="Typo.body2">Line 2 text</MudText>
    </TooltipContent>
</MudTooltip>

Try online: https://try.mudblazor.com/snippet/wOQQPYbhQmuAymWu

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
0

Use white-space: pre-line;. Add this class to your app.css file:

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

And add it to the tooltip:

<MudTooltip Text="@tooltipText" Class="white-space-pre-line" ...>
    ...
</MudTooltip>

Check: Line break in HTML with '\n'

Dimitris Maragkos
  • 8,932
  • 2
  • 8
  • 26