Highlighter

Use this utility component to highlight parts of the text.

Usage

The highlighter can be used in combination with any other component.

Search, appearance

Multiple Highlights

In addition to HighlightedText property which accepts a single text fragment in the form of an string, the HighlightedTexts property accepts an enumerable of strings which can be used to highlight several text fragments.

William Jordan

Oliver Jones

William Johnson

Daniel Williams

Oliver Simpson

<MudPaper Elevation="0">
    <MudList>
        <MudListSubheader>
            <MudTextField @bind-Value="searchTerm" AdornmentIcon="@Icons.Material.Filled.People"
                          Adornment="Adornment.End" Immediate="true" Variant="Variant.Outlined"
                          Label="Names to search"/>
        </MudListSubheader>

        @{
            string[] searchTerms = searchTerm.Split(split);
            for (int i = 0; i < searchTerms.Length; i++)
                searchTerms[i] = searchTerms[i].Trim();
        }
        @foreach (var name in names)
        {
            <MudListItem @key="name" Icon="@Icons.Material.Filled.Person">
                <MudHighlighter Text="@name" HighlightedTexts="@searchTerms" />
            </MudListItem>
        }
    </MudList>
</MudPaper>
@code {
    string searchTerm = "William Jordan, Oliver";
    IEnumerable<string> names = new List<string>
    {
        "William Jordan", "Oliver Jones", "William Johnson", "Daniel Williams", "Oliver Simpson"
    };
    static readonly char[] split = new char[] { ';', ',', '.' };
}

Copyright © 2020-2024 MudBlazor.

Powered by .NET 8.0.8

An error has occurred. This application may no longer respond until reloaded. Reload 🗙