Skip to content

Commit

Permalink
#886 [HxCheckbox] [HxSwitch] Use Text instead of Yes/No for chips
Browse files Browse the repository at this point in the history
  • Loading branch information
hakenr committed Nov 12, 2024
1 parent 13f8fbd commit e10a5ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion BlazorAppTest/Pages/InputsTest.razor
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
@bind-Value="@model.CultureInfoMultiSelectNames" />


<HxSwitch Text="Switch" @bind-Value="@context.BoolSwitch" ValidationMessageMode="@validationMessageMode" />
<HxSwitch Label="Settings" Text="Switch" @bind-Value="@context.BoolSwitch" ValidationMessageMode="@validationMessageMode" />

<HxSubmit Icon="@BootstrapIcon.Check" Color="ThemeColor.Primary">Submit</HxSubmit>
</HxFilterForm>
Expand Down
12 changes: 11 additions & 1 deletion Havit.Blazor.Components.Web.Bootstrap/Forms/HxCheckbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ protected override void RenderChipLabel(RenderTreeBuilder builder)

protected override void RenderChipValue(RenderTreeBuilder builder)
{
builder.AddContent(0, CurrentValue ? Localizer["ChipValueTrue"] : Localizer["ChipValueFalse"]);
// #886 [HxCheckbox] [HxSwitch] Use Text instead of Yes/No for chips
// If both Text and Label are set, use Text for the positive chip value.
// BTW: Negative value is currently never used as chip is rendered only if the value is not equal to default(TValue).
// This might need additional attention if we implement support for three-state checkboxes
// or allow setting neutral value other than default(TValue).
string positiveValue = Localizer["ChipValueTrue"];
if (!String.IsNullOrWhiteSpace(Text) && !String.IsNullOrWhiteSpace(Label))
{
positiveValue = Text;
}
builder.AddContent(0, CurrentValue ? positiveValue : Localizer["ChipValueFalse"]);
}
}

0 comments on commit e10a5ab

Please sign in to comment.