MudBlazor icon indicating copy to clipboard operation
MudBlazor copied to clipboard

MudToggleGroup doesn't cascade nullable value type

Open danielchalmers opened this issue 2 years ago • 3 comments

Bug type

Component

Component name

MudToggleGroup

What happened?

Creating a MudToggleGroup for an int? will make it vertical and unselectable due to _items not filling correctly resulting in the invalid value: grid-template-columns: repeat(0, minmax(0, 1fr)).

I use the int? to be null when none are selected like when an item is toggled off.

image

<MudToggleGroup T="int?" @bind-Value="Point.ScaleIndex" SelectionMode="SelectionMode.ToggleSelection" Color="Color.Primary" Dense CheckMark FixedContent>
	<MudToggleItem Value="0"><MudText Typo="Typo.subtitle2">None</MudText></MudToggleItem>
	<MudToggleItem Value="1"><MudText Typo="Typo.subtitle2">Low</MudText></MudToggleItem>
	<MudToggleItem Value="3"><MudText Typo="Typo.subtitle2">Medium</MudText></MudToggleItem>
	<MudToggleItem Value="5"><MudText Typo="Typo.subtitle2">High</MudText></MudToggleItem>
</MudToggleGroup>

Expected behavior

Items should be horizontal, selectable, and none being selected should make Value null.

Reproduction link

https://try.mudblazor.com/snippet/cuGIkGmyYndnLmCx

Reproduction steps

...

Relevant log output

No response

Version (bug)

6.15.0

Version (working)

No response

What browsers are you seeing the problem on?

Microsoft Edge

On what operating system are you experiencing the issue?

Windows

Pull Request

  • [ ] I would like to do a Pull Request

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

danielchalmers avatar Feb 24 '24 00:02 danielchalmers

It seems like if you explicitly add T to the MudToggleItem it works correctly https://try.mudblazor.com/snippet/caGeEcGoenvqZlte

I'm not sure why the [CascadingTypeParameter(nameof(T))] is not working fully correctly.

ScarletKuro avatar Feb 24 '24 12:02 ScarletKuro

This also works for me: <MudToggleItem Value="@((int?)42)">

zimmer62 avatar Mar 14 '24 13:03 zimmer62

https://github.com/dotnet/razor/issues/10201

danielchalmers avatar Apr 04 '24 19:04 danielchalmers