Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
@for (int i = 0; i < (MaxChips == 0 ? _valuesState.Value?.Count ?? 0 : (MaxChips < (_valuesState.Value?.Count ?? 0) ? MaxChips : _valuesState.Value?.Count ?? 0)); i++)
{
int a = i;
<MudChip T="T" Class="@ClassChip" Style="@StyleChip" Ripple="false" Text="@(_valuesState.Value != null ? _valuesState.Value[a] : string.Empty)" Color="@ChipColor" Variant="@ChipVariant" Size="@ChipSize" Disabled="@Disabled" />
<MudChip T="T" Class="@ClassChip" Style="@StyleChip" Ripple="false" Text="@(_valuesState.Value != null ? _valuesState.Value[a] : string.Empty)" Color="@ChipColor" Variant="@ChipVariant" Size="@ChipSize" Disabled="@GetDisabledState()" />
}
</MudChipSet>
@if (_valuesState.Value != null && MaxChips != 0 && MaxChips < _valuesState.Value.Count)
{
<MudChip T="T" Ripple="false" Text="@($"+{_valuesState.Value.Count - MaxChips}")" Color="@ChipColor" Variant="@ChipVariant" Size="@ChipSize" Disabled="@Disabled" />
<MudChip T="T" Ripple="false" Text="@($"+{_valuesState.Value.Count - MaxChips}")" Color="@ChipColor" Variant="@ChipVariant" Size="@ChipSize" Disabled="@GetDisabledState()" />
}
</DataVisualiser>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ protected async Task SetChips()
/// <returns></returns>
public async Task Closed(MudChip<T> chip)
{
if (Disabled || ReadOnly)
if (GetDisabledState() || GetReadOnlyState())
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@namespace MudExtensions.UnitTests.TestComponents

<MudSwitch T="bool" @bind-Value="FormDisabled" Label="Form Disabled" Color="Color.Primary" />
<MudSwitch T="bool" @bind-Value="FormReadOnly" Label="Form ReadOnly" Color="Color.Primary" />

<MudForm Disabled="@FormDisabled" ReadOnly="@FormReadOnly">
<MudChipField T="string" @bind-Values="Values" Label="Chip Field" Variant="Variant.Outlined" />
</MudForm>

@code {
public static string __description__ = "Chips should respect the parent form's Disabled and ReadOnly state";

[Parameter]
public bool FormDisabled { get; set; }

[Parameter]
public bool FormReadOnly { get; set; }

[Parameter]
public List<string>? Values { get; set; } = new() { "first", "second" };
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Bunit;
using AwesomeAssertions;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using MudBlazor.Extensions;
using MudExtensions.UnitTests.TestComponents;

namespace MudExtensions.UnitTests.Components
{
Expand All @@ -21,5 +23,36 @@ public async Task ChipFieldBasicTest()
comp.Instance.GetState(x => x.Values).Should().BeEquivalentTo(new List<string> { "asdf", "asd", "sdfg" });
comp.Instance.GetState(x => x.Value).Should().BeEquivalentTo(null);
}

[Test]
public async Task ChipField_ParentFormDisabled_ShouldDisableChipsAndPreventRemoval()
{
var comp = Context.Render<ChipFieldFormStateTest>(opt =>
{
opt.Add(a => a.FormDisabled, true);
});
var chipField = comp.FindComponent<MudChipField<string>>();
var chips = comp.FindComponents<MudChip<string>>();

chips.Should().HaveCount(2);
chips.Should().AllSatisfy(chip => chip.Instance.Disabled.Should().BeTrue());

await comp.InvokeAsync(() => chipField.Instance.Closed(chips[0].Instance));
chipField.Instance.GetState(x => x.Values).Should().BeEquivalentTo(new List<string> { "first", "second" });
}

[Test]
public async Task ChipField_ParentFormReadOnly_ShouldPreventRemoval()
{
var comp = Context.Render<ChipFieldFormStateTest>(opt =>
{
opt.Add(a => a.FormReadOnly, true);
});
var chipField = comp.FindComponent<MudChipField<string>>();
var chips = comp.FindComponents<MudChip<string>>();

await comp.InvokeAsync(() => chipField.Instance.Closed(chips[0].Instance));
chipField.Instance.GetState(x => x.Values).Should().BeEquivalentTo(new List<string> { "first", "second" });
}
}
}