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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@

@if (IsVisible)
{
<div tabindex="0" @attributes="UserAttributes" id="@ItemId" class="@Classname" @onclick="@(((MudListExtended?.Clickable == true || NestedList != null) && IsFunctional == false) ? OnClickHandler : OnlyOnClick)" @onclick:stopPropagation="@OnClickStopPropagation" style="@Style">
<div tabindex="0" @attributes="UserAttributes" id="@ItemId" class="@Classname"
role="option"
aria-selected="@(_selected ? "true" : "false")"
aria-label="@AccessibleName"
@onclick="@(((MudListExtended?.Clickable == true || NestedList != null) && IsFunctional == false) ? OnClickHandler : OnlyOnClick)" @onclick:stopPropagation="@OnClickStopPropagation" style="@Style">

@if (MudListExtended?.ItemDisabledTemplate != null && GetDisabledStatus() == true)
{
{
@MudListExtended.ItemDisabledTemplate(this)
}
else if (MudListExtended?.ItemSelectedTemplate != null && IsSelected == true)
Expand All @@ -27,15 +31,18 @@
<div class="@MultiSelectClassName">
@if (OverrideMultiSelectionComponent == null ? MudListExtended?.MultiSelectionComponent == MultiSelectionComponent.CheckBox : OverrideMultiSelectionComponent.Value == MultiSelectionComponent.CheckBox)
{
<MudCheckBox Color="@(MudListExtended?.Color ?? Color.Default)" Disabled="@GetDisabledStatus()" @bind-Value="_selected" @onclick="OnClickHandler" Dense="true" />
<MudCheckBox Color="@(MudListExtended?.Color ?? Color.Default)" Disabled="@GetDisabledStatus()" @bind-Value="_selected" @onclick="OnClickHandler" Dense="true"
aria-label="@($"Select {AccessibleName}")" />
}
else if (OverrideMultiSelectionComponent == null ? MudListExtended?.MultiSelectionComponent == MultiSelectionComponent.Switch : OverrideMultiSelectionComponent.Value == MultiSelectionComponent.Switch)
{
<MudSwitch Color="@(MudListExtended?.Color ?? Color.Default)" Disabled="@GetDisabledStatus()" @bind-Value="_selected" @onclick="OnClickHandler" StopClickPropagation="true" />
<MudSwitch Color="@(MudListExtended?.Color ?? Color.Default)" Disabled="@GetDisabledStatus()" @bind-Value="_selected" @onclick="OnClickHandler" StopClickPropagation="true"
aria-label="@($"Select {AccessibleName}")" />
}
else if (OverrideMultiSelectionComponent == null ? MudListExtended?.MultiSelectionComponent == MultiSelectionComponent.SwitchM3 : OverrideMultiSelectionComponent.Value == MultiSelectionComponent.SwitchM3)
{
<MudSwitchM3 Class="mr-4" Color="@(MudListExtended?.Color ?? Color.Default)" Disabled="@GetDisabledStatus()" @bind-Value="_selected" @onclick="OnClickHandler" StopClickPropagation="true" />
<MudSwitchM3 Class="mr-4" Color="@(MudListExtended?.Color ?? Color.Default)" Disabled="@GetDisabledStatus()" @bind-Value="_selected" @onclick="OnClickHandler" StopClickPropagation="true"
aria-label="@($"Select {AccessibleName}")" />
}
</div>
}
Expand Down Expand Up @@ -75,15 +82,18 @@
<div class="@MultiSelectClassName">
@if (OverrideMultiSelectionComponent == null ? MudListExtended?.MultiSelectionComponent == MultiSelectionComponent.CheckBox : OverrideMultiSelectionComponent.Value == MultiSelectionComponent.CheckBox)
{
<MudCheckBox Color="@(MudListExtended?.Color ?? Color.Default)" Disabled="@GetDisabledStatus()" @bind-Value="_selected" @onclick="OnClickHandler" Dense="true" />
<MudCheckBox Color="@(MudListExtended?.Color ?? Color.Default)" Disabled="@GetDisabledStatus()" @bind-Value="_selected" @onclick="OnClickHandler" Dense="true"
aria-label="@($"Select {AccessibleName}")" />
}
else if (OverrideMultiSelectionComponent == null ? MudListExtended?.MultiSelectionComponent == MultiSelectionComponent.Switch : OverrideMultiSelectionComponent.Value == MultiSelectionComponent.Switch)
{
<MudSwitch Color="@(MudListExtended?.Color ?? Color.Default)" Disabled="@GetDisabledStatus()" @bind-Value="_selected" @onclick="OnClickHandler" StopClickPropagation="true" />
<MudSwitch Color="@(MudListExtended?.Color ?? Color.Default)" Disabled="@GetDisabledStatus()" @bind-Value="_selected" @onclick="OnClickHandler" StopClickPropagation="true"
aria-label="@($"Select {AccessibleName}")" />
}
else if (OverrideMultiSelectionComponent == null ? MudListExtended?.MultiSelectionComponent == MultiSelectionComponent.SwitchM3 : OverrideMultiSelectionComponent.Value == MultiSelectionComponent.SwitchM3)
{
<MudSwitchM3 Color="@(MudListExtended?.Color ?? Color.Default)" Disabled="@GetDisabledStatus()" @bind-Value="_selected" @onclick="OnClickHandler" StopClickPropagation="true" />
<MudSwitchM3 Color="@(MudListExtended?.Color ?? Color.Default)" Disabled="@GetDisabledStatus()" @bind-Value="_selected" @onclick="OnClickHandler" StopClickPropagation="true"
aria-label="@($"Select {AccessibleName}")" />
}
</div>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Windows.Input;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using MudBlazor.Extensions;
using MudBlazor.Utilities;
using MudBlazor;

Expand Down Expand Up @@ -59,7 +57,29 @@ public partial class MudListItemExtended<T> : MudComponentBase, IDisposable
/// <summary>
///
/// </summary>
protected internal string? ItemId { get; } = "listitem_" + Guid.NewGuid().ToString().Substring(0, 8);
protected internal string? ItemId { get; } = string.Concat("listitem_", Guid.NewGuid().ToString().AsSpan(0, 8));

/// <summary>
/// The accessible name used for the item. Prefer Text, then SecondaryText, then Value.ToString().
/// If the parent list has a ToStringFunc use that for Value formatting.
/// </summary>
protected string AccessibleName
{
get
{
if (!string.IsNullOrWhiteSpace(Text))
return Text!;
if (!string.IsNullOrWhiteSpace(SecondaryText))
return SecondaryText!;
if (Value != null)
{
if (MudListExtended?.ToStringFunc != null)
return MudListExtended.ToStringFunc(Value) ?? Value.ToString() ?? string.Empty;
return Value.ToString() ?? string.Empty;
}
return string.Empty;
}
}

/// <summary>
/// Functional items does not hold values. If a value set on Functional item, it ignores by the MudList. They can not count on Items list (they count on AllItems), cannot be subject of keyboard navigation and selection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,41 @@ public void SelectLabelFor()
label[0].Attributes.GetNamedItem("for")?.Value.Should().Be("selectLabelTest");
}

[Test]
public void Select_Items_Should_Expose_Accessible_Role_And_Label()
{
var comp = Context.Render<SelectTest1>();
comp.Find("div.mud-input-control").Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));

var items = comp.FindAll("div.mud-list-item-extended").ToArray();
var item = items[1];
item.GetAttribute("role").Should().Be("option");
item.GetAttribute("aria-selected").Should().Be("false");
var ariaLabel = item.GetAttribute("aria-label");
ariaLabel.Should().NotBeNullOrEmpty();
ariaLabel.Trim().Should().Be("2");
}

[Test]
public void MultiSelect_Items_Should_Expose_Checkbox_AriaLabel_And_TestId()
{
var comp = Context.Render<MultiSelectTest1>();
comp.Find("div.mud-input-control").Click();
comp.WaitForAssertion(() => comp.FindAll("div.mud-list-item-extended").Count.Should().BeGreaterThan(0));

var items = comp.FindAll("div.mud-list-item-extended").ToArray();
var item = items[1];
item.GetAttribute("role").Should().Be("option");
var checkbox = item.QuerySelector("input[type=checkbox]");
checkbox.Should().NotBeNull();
var optionAria = item.GetAttribute("aria-label");
optionAria.Should().NotBeNullOrEmpty();
var checkboxAria = checkbox.GetAttribute("aria-label");
checkboxAria.Should().NotBeNullOrEmpty();
checkboxAria.Trim().Should().Be($"Select {optionAria.Trim()}");
}

// Note: MudSelect doesn't guaranteed the consequences of changing Value if MultiSelection is true for now.
// When this feature will add, just uncomment the testcase to test it. No need to write new test.
[Test]
Expand Down
Loading