Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@namespace MudExtensions.UnitTests.TestComponents
<MudPopoverProvider></MudPopoverProvider>

<MudForm Disabled="true">
<MudSelectExtended T="string" @bind-Value="value" PopoverClass="select-popover-class">
<MudSelectItemExtended Value="@("1")" />
<MudSelectItemExtended Value="@("2")" />
</MudSelectExtended>
</MudForm>

@code {
string? value = null;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@namespace MudExtensions.UnitTests.TestComponents
<MudPopoverProvider></MudPopoverProvider>

<MudSelectExtended T="string" @bind-Value="value" PopoverClass="select-popover-class" onfocus="Focused" OnBlur="Blurred">
<MudSelectExtended T="string" @bind-Value="value" PopoverClass="select-popover-class" Disabled="@Disabled" onfocus="Focused" OnBlur="Blurred">
<MudSelectItemExtended Value="@("1")"/>
<MudSelectItemExtended Value="@("2")"/>
<MudSelectItemExtended Value="@("3")"/>
Expand All @@ -11,18 +11,21 @@
<MudSwitch @bind-Value="@_focused" />

@code {
public static string __description__ = "Click should open the Menu and selecting a value should update the bindable value.";
public static string __description__ = "Click should open the Menu and selecting a value should update the bindable value.";

string? value = null;
bool _focused = false;
[Parameter]
public bool Disabled { get; set; }

private void Focused()
{
_focused = true;
}
string? value = null;
bool _focused = false;

private void Blurred()
{
_focused = false;
}
private void Focused()
{
_focused = true;
}

private void Blurred()
{
_focused = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public void SingleSelect_Should_FireTextChangedBeforeSelectedValuesChanged()
string.Join(",", selectedValues ?? new List<string>()).Should().Be("2");

input.Click();
comp.WaitForAssertion(()=>comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));
items = comp.FindAll("div.mud-list-item-extended").ToArray();

items[0].Click();
Expand Down Expand Up @@ -713,7 +713,7 @@ public void SingleSelect_Should_CallValidationFunc()

comp.FindAll("div.mud-list-item-extended")[1].Click();
// menu should be closed now
comp.WaitForAssertion(() => menu.ClassList.Should().NotContain("mud-popover-open"));
comp.WaitForAssertion(() => comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open"));
comp.WaitForAssertion(() => select.Instance.Value.Should().Be("2"));
select.Instance.Text.Should().Be("2");
validatedValue.Should().Be("2");
Expand Down Expand Up @@ -1333,5 +1333,35 @@ await comp.InvokeAsync(() =>
select.SelectedValues?.Count().Should().Be(1);
select.Text.Should().Be("test");
}

[Test]
public void Select_Should_NotOpen_WhenDisabled()
{
var comp = Context.RenderComponent<SelectTest1>(parameters =>
{
parameters.Add(p => p.Disabled, true);
});
var select = comp.FindComponent<MudSelectExtended<string>>();
var input = comp.Find("div.mud-input-control");

// Try to open the select
input.Click();
// The menu should not open
comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open");
}

[Test]
public void Select_Should_NotOpen_WhenParentDisabled()
{
// Use a test component that wraps the select in a disabled parent
var comp = Context.RenderComponent<DisabledParentSelectTest>();
var select = comp.FindComponent<MudSelectExtended<string>>();
var input = comp.Find("div.mud-input-control");

// Try to open the select
input.Click();
// The menu should not open
comp.Find("div.mud-popover").ClassList.Should().NotContain("mud-popover-open");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
/// <summary>
///
/// </summary>
protected Dictionary<T, MudSelectItemExtended<T?>> _valueLookup = new();

Check warning on line 45 in CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs

View workflow job for this annotation

GitHub Actions / build

The type 'T' cannot be used as type parameter 'TKey' in the generic type or method 'Dictionary<TKey, TValue>'. Nullability of type argument 'T' doesn't match 'notnull' constraint.
/// <summary>
///
/// </summary>
protected Dictionary<T, MudSelectItemExtended<T?>> _shadowLookup = new();

Check warning on line 49 in CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs

View workflow job for this annotation

GitHub Actions / build

The type 'T' cannot be used as type parameter 'TKey' in the generic type or method 'Dictionary<TKey, TValue>'. Nullability of type argument 'T' doesn't match 'notnull' constraint.
private MudInputExtended<string> _elementReference = new();
internal bool _isOpen;
/// <summary>
Expand Down Expand Up @@ -850,7 +850,7 @@
/// <param name="obj"></param>
protected internal async Task HandleKeyDownAsync(KeyboardEventArgs obj)
{
if (Disabled || ReadOnly)
if (GetDisabledState() || GetReadOnlyState())
return;

if (_list != null && _isOpen)
Expand Down Expand Up @@ -997,7 +997,7 @@
/// <returns></returns>
public async Task ToggleMenu()
{
if (Disabled || ReadOnly)
if (GetDisabledState() || GetReadOnlyState())
return;
if (_isOpen)
await CloseMenu();
Expand All @@ -1011,7 +1011,7 @@
/// <returns></returns>
public async Task OpenMenu()
{
if (Disabled || ReadOnly)
if (GetDisabledState() || GetReadOnlyState())
return;
_isOpen = true;
UpdateIcon();
Expand Down
Loading