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

feat(Select): add IsMarkupString parameter #2461

Merged
merged 6 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/BootstrapBlazor/Components/Select/MultiSelect.razor
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@
<div class="form-check">
<input class="form-check-input" type="checkbox" disabled="@CheckCanSelect(item)" checked="@GetCheckedString(item)" />
</div>
@if (ItemTemplate == null)
@if (ItemTemplate != null)
{
<span>@item.Text</span>
@ItemTemplate(item)
}
else if (IsMarkupString)
{
@((MarkupString)item.Text)
}
else
{
@ItemTemplate(item)
<span>@item.Text</span>
}
</div>
</DynamicElement>
Expand Down
4 changes: 4 additions & 0 deletions src/BootstrapBlazor/Components/Select/Select.razor
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
{
@ItemTemplate(item)
}
else if (IsMarkupString)
{
@((MarkupString)item.Text)
}
else
{
@item.Text
Expand Down
6 changes: 6 additions & 0 deletions src/BootstrapBlazor/Components/Select/SelectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public abstract class SelectBase<TValue> : PopoverSelectBase<TValue>
[Parameter]
public string? SearchIcon { get; set; }

/// <summary>
/// 获得/设置 是否为 MarkupString 默认 false
/// </summary>
[Parameter]
public bool IsMarkupString { get; set; }

/// <summary>
/// 获得/设置 字符串比较规则 默认 StringComparison.OrdinalIgnoreCase 大小写不敏感
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions test/UnitTest/Components/MultiSelectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,20 @@ public void ClearIcon_Ok()
});
Assert.Contains("fa-solid fa-xmark", cut.Markup);
}

[Fact]
public void IsMarkupString_Ok()
{
var cut = Context.RenderComponent<MultiSelect<string>>(pb =>
{
pb.Add(a => a.Items, new SelectedItem[]
{
new("1", "<div>Test1</div>"),
new("2", "<div>Test2</div>")
});
pb.Add(a => a.Value, "2");
pb.Add(a => a.IsMarkupString, true);
});
Assert.Contains("<div>Test1</div>", cut.Markup);
}
}
16 changes: 16 additions & 0 deletions test/UnitTest/Components/SelectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -784,4 +784,20 @@ public void TryParseValueFromString_Ok()
value = "1";
mi?.Invoke(select, new object?[] { value, result, msg });
}

[Fact]
public void IsMarkupString_Ok()
{
var cut = Context.RenderComponent<Select<string>>(pb =>
{
pb.Add(a => a.Items, new SelectedItem[]
{
new("1", "<div>Test1</div>"),
new("2", "<div>Test2</div>")
});
pb.Add(a => a.Value, "2");
pb.Add(a => a.IsMarkupString, true);
});
Assert.Contains("<div>Test1</div>", cut.Markup);
}
}