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
Expand Up @@ -5,137 +5,147 @@

<CascadingValue Name="Standalone" Value="false" IsFixed="true">
<CascadingValue Value="@this" IsFixed="true">
<div class="mud-select-extended" id="@_elementId">
<MudInputControl Label="@Label" Variant="@Variant" HelperText="@HelperText" HelperTextOnFocus="@HelperTextOnFocus" FullWidth="@FullWidth" Margin="@Margin" Class="@Classname" Style="@Style"
Error="@Error" ErrorText="@ErrorText" ErrorId="@ErrorId" Disabled="@Disabled" @onclick="@ToggleMenu" Required="@Required" ForId="@FieldId">
<InputContent>
<MudInputExtended @ref="_elementReference" InputType="InputType.Hidden" MockInputStyle="@(ValuePresenter == ValuePresenter.Chip ? "width: 0px" : null)"
Class="@InputClassname" Style="@InputStyle" Margin="@Margin" Placeholder="@Placeholder"
Variant="@Variant"
TextUpdateSuppression="false"
Value="@(Strict && !IsValueInList ? null : Text)" DisableUnderLine="@DisableUnderLine"
Disabled="@Disabled" ReadOnly="true" Error="@Error" ErrorId="@ErrorId"
Clearable="@Clearable" OnClearButtonClick="(async (e) => await SelectClearButtonClickHandlerAsync(e))"
@attributes="UserAttributes" OnBlur="@OnLostFocus" ForceShrink="@ForceShrink">
<div class="mud-select-extended" id="@_elementId">
<MudInputControl Label="@Label" Variant="@Variant" HelperText="@HelperText" HelperTextOnFocus="@HelperTextOnFocus" FullWidth="@FullWidth" Margin="@Margin" Class="@Classname" Style="@Style"
Error="@Error" ErrorText="@ErrorText" ErrorId="@ErrorId" Disabled="@Disabled" @onclick="@ToggleMenu" Required="@Required" ForId="@FieldId">
<InputContent>
<MudInputExtended @ref="_elementReference" InputType="InputType.Hidden" MockInputStyle="@(ValuePresenter == ValuePresenter.Chip ? "width: 0px" : null)"
Class="@InputClassname" Style="@InputStyle" Margin="@Margin" Placeholder="@Placeholder"
Variant="@Variant"
TextUpdateSuppression="false"
Value="@(Strict && !IsValueInList ? null : Text)" DisableUnderLine="@DisableUnderLine"
Disabled="@Disabled" ReadOnly="true" Error="@Error" ErrorId="@ErrorId"
Clearable="@Clearable" OnClearButtonClick="(async (e) => await SelectClearButtonClickHandlerAsync(e))"
@attributes="UserAttributes" OnBlur="@OnLostFocus" ForceShrink="@ForceShrink">

<AdornmentEnd>
<MudIcon Icon="@_currentIcon" Color="@AdornmentColor" Size="@IconSize" @onclick="OnAdornmentClick" />
</AdornmentEnd>
<AdornmentEnd>
<MudIcon Icon="@_currentIcon" Color="@AdornmentColor" Size="@IconSize" @onclick="OnAdornmentClick" />
</AdornmentEnd>

<DataVisualiser>
@if (ValuePresenter == ValuePresenter.Chip)
{
<MudChipSet Class="d-flex flex-wrap mud-width-full" Style="row-gap: 4px" AllClosable="ChipCloseable" OnClose="ChipClosed">
@foreach (var item in Items?.Where(x => SelectedValues.Contains(x.Value)) ?? new List<MudSelectItemExtended<T>>())
{
<MudChip Class="@ChipClass" Value="item.Value" Text="@(string.IsNullOrEmpty(item.Text) ? Converter.Set(item.Value) : item.Text)" Color="@Color" Size="@ChipSize" Variant="@ChipVariant" />
}
</MudChipSet>
}
</DataVisualiser>

<ChildContent>
<div class="@TemplateClass">
@if (Strict && !IsValueInList)
<DataVisualiser>
@if (ValuePresenter == ValuePresenter.Chip)
{
//Show nothing
<MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText>
<MudChipSet Class="d-flex flex-wrap mud-width-full" Style="row-gap: 4px" AllClosable="ChipCloseable" OnClose="ChipClosed">
@if (ItemCollection != null)
{
foreach (var item in ItemCollection.Where(x => SelectedValues.Contains(x)))
{
<MudChip Class="@ChipClass" Value="@item" Text="@Converter.Set(item)" Color="@Color" Size="@ChipSize" Variant="@ChipVariant" />
}
}
else
{
foreach (var item in Items?.Where(x => SelectedValues.Contains(x.Value)) ?? new List<MudSelectItemExtended<T>>())
{
<MudChip Class="@ChipClass" Value="item.Value" Text="@(string.IsNullOrEmpty(item.Text) ? Converter.Set(item.Value) : item.Text)" Color="@Color" Size="@ChipSize" Variant="@ChipVariant" />
}
}
</MudChipSet>
}
else if (ValuePresenter == ValuePresenter.Text)
{
@if (string.IsNullOrEmpty(Text))
{
<MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText>
}
</DataVisualiser>

<MudRender>@GetSelectTextPresenter()</MudRender>
}
else if (ValuePresenter == ValuePresenter.Chip)
{
if (SelectedValues == null || !SelectedValues.Any())
<ChildContent>
<div class="@TemplateClass">
@if (Strict && !IsValueInList)
{
//Show nothing
<MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText>
}
else
{
@*Chips show under DataVisualiser RenderFragment*@
}
}
else if (ValuePresenter == ValuePresenter.ItemContent)
{
if (SelectedListItem == null)
else if (ValuePresenter == ValuePresenter.Text)
{
<MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText>
@if (string.IsNullOrEmpty(Text))
{
<MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText>
}

<MudRender>@GetSelectTextPresenter()</MudRender>
}
else if (ItemTemplate != null)
else if (ValuePresenter == ValuePresenter.Chip)
{
if (SelectedListItem != null && SelectedListItem.Value != null)
if (SelectedValues == null || !SelectedValues.Any())
{
@ItemTemplate(SelectedListItem)
<MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText>
}
else if (!string.IsNullOrEmpty(Placeholder))
else
{
<MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText>
@*Chips show under DataVisualiser RenderFragment*@
}
}
else if (SelectedListItem.ChildContent != null)
{
<MudRender>@SelectedListItem.ChildContent</MudRender>
}
else
else if (ValuePresenter == ValuePresenter.ItemContent)
{
@if (string.IsNullOrEmpty(Text))
if (SelectedListItem == null)
{
<MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText>

}
else if (ItemTemplate != null)
{
if (SelectedListItem != null && SelectedListItem.Value != null)
{
@ItemTemplate(SelectedListItem)
}
else if (!string.IsNullOrEmpty(Placeholder))
{
<MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText>
}
}
else if (SelectedListItem.ChildContent != null)
{
<MudRender>@SelectedListItem.ChildContent</MudRender>
}
else
{
@if (string.IsNullOrEmpty(Text))
{
<MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText>
}

<MudRender>@GetSelectTextPresenter()</MudRender>
<MudRender>@GetSelectTextPresenter()</MudRender>
}
}
}
</div>
</ChildContent>
</MudInputExtended>
</div>
</ChildContent>
</MudInputExtended>

<MudPopover Open="@_isOpen" MaxHeight="@MaxHeight" AnchorOrigin="@AnchorOrigin" TransformOrigin="@TransformOrigin" Class="@PopoverClass" RelativeWidth="@RelativeWidth">
<CascadingValue Value="@this" IsFixed="true">
<MudListExtended @ref="@_list" T="T" @bind-SelectedValue="@Value" @bind-SelectedValues="@SelectedValues" @bind-SelectedItem="@SelectedListItem" @bind-SelectedItems="@SelectedListItems"
Clickable="true" Color="@Color" Dense="@Dense" ItemCollection="@ItemCollection" Virtualize="@Virtualize" DisablePadding="@DisablePopoverPadding" DisableSelectedItemStyle="@DisableSelectedItemStyle"
MultiSelection="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MultiSelectionAlign="@MultiSelectionAlign" SelectAll="@SelectAll" SelectAllPosition="@SelectAllPosition" SelectAllText="@SelectAllText"
CheckedIcon="@CheckedIcon" UncheckedIcon="@UncheckedIcon" IndeterminateIcon="@IndeterminateIcon" SelectValueOnTab="@SelectValueOnTab" Comparer="@Comparer"
ItemTemplate="@ItemTemplate" ItemSelectedTemplate="@ItemSelectedTemplate" ItemDisabledTemplate="@ItemDisabledTemplate" SearchBox="@SearchBox" SearchBoxAutoFocus="@SearchBoxAutoFocus" SearchFunc="@SearchFunc" SearchBoxPlaceholder="@SearchBoxPlaceholder" SearchBoxClearable="@SearchBoxClearable" ToStringFunc="@ToStringFunc">
@ChildContent
</MudListExtended>
</CascadingValue>
</MudPopover>
</InputContent>
</MudInputControl>
</div>
<CascadingValue Value="@this" IsFixed="true">
<MudListExtended @ref="@_list" T="T" @bind-SelectedValue="@Value" @bind-SelectedValues="@SelectedValues" @bind-SelectedItem="@SelectedListItem" @bind-SelectedItems="@SelectedListItems"
Clickable="true" Color="@Color" Dense="@Dense" ItemCollection="@ItemCollection" Virtualize="@Virtualize" DisablePadding="@DisablePopoverPadding" DisableSelectedItemStyle="@DisableSelectedItemStyle"
MultiSelection="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MultiSelectionAlign="@MultiSelectionAlign" SelectAll="@SelectAll" SelectAllPosition="@SelectAllPosition" SelectAllText="@SelectAllText"
CheckedIcon="@CheckedIcon" UncheckedIcon="@UncheckedIcon" IndeterminateIcon="@IndeterminateIcon" SelectValueOnTab="@SelectValueOnTab" Comparer="@Comparer"
ItemTemplate="@ItemTemplate" ItemSelectedTemplate="@ItemSelectedTemplate" ItemDisabledTemplate="@ItemDisabledTemplate" SearchBox="@SearchBox" SearchBoxAutoFocus="@SearchBoxAutoFocus" SearchFunc="@SearchFunc" SearchBoxPlaceholder="@SearchBoxPlaceholder" SearchBoxClearable="@SearchBoxClearable" ToStringFunc="@ToStringFunc">
@ChildContent
</MudListExtended>
</CascadingValue>
</MudPopover>
</InputContent>
</MudInputControl>
</div>

@*To Be Discussed as Second ShadowItems: Needed to render directly into select to has initial values*@
@*To Be Discussed as Second ShadowItems: Needed to render directly into select to has initial values*@

<div style="display: none">
<CascadingValue Value="@this" IsFixed="true">
<div style="display: none">
<CascadingValue Value="@this" IsFixed="true">
<MudListExtended T="T" @bind-SelectedValue="@Value" @bind-SelectedValues="@SelectedValues" @bind-SelectedItem="@SelectedListItem" @bind-SelectedItems="@SelectedListItems"
Clickable="true" Color="@Color" Dense="@Dense" ItemCollection="@ItemCollection" Virtualize="@Virtualize" DisablePadding="@DisablePopoverPadding" DisableSelectedItemStyle="@DisableSelectedItemStyle"
MultiSelection="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MultiSelectionAlign="@MultiSelectionAlign" SelectAll="@SelectAll" SelectAllPosition="@SelectAllPosition" SelectAllText="@SelectAllText"
CheckedIcon="@CheckedIcon" UncheckedIcon="@UncheckedIcon" IndeterminateIcon="@IndeterminateIcon" SelectValueOnTab="@SelectValueOnTab" Comparer="@Comparer"
ItemTemplate="@ItemTemplate" ItemSelectedTemplate="@ItemSelectedTemplate" ItemDisabledTemplate="@ItemDisabledTemplate" SearchBox="@SearchBox" SearchBoxAutoFocus="@SearchBoxAutoFocus" SearchFunc="@SearchFunc" SearchBoxPlaceholder="@SearchBoxPlaceholder" SearchBoxClearable="@SearchBoxClearable" ToStringFunc="@ToStringFunc">
@ChildContent
</MudListExtended>
@ChildContent
</MudListExtended>
</CascadingValue>
</div>
</div>
</CascadingValue>

@*Shadow select items for IsValueInList and CanRenderValue*@
<CascadingValue Value="@((IMudShadowSelectExtended)this)" IsFixed="true">
<CascadingValue Name="HideContent" Value="true">
@ChildContent
</CascadingValue>
</CascadingValue>
@ChildContent
</CascadingValue>
</CascadingValue>




</CascadingValue>
<!-- mousedown instead of click needed to close the menu before OnLostFocus runs -->
<MudOverlay Visible="_isOpen" @onmousedown="@(() => CloseMenu())" LockScroll="@LockScroll" />
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public MudSelectExtended()
.Build();

private string _elementId = "select_" + Guid.NewGuid().ToString().Substring(0, 8);
private string _popoverId = "selectpopover_" + Guid.NewGuid().ToString().Substring(0, 8);

/// <summary>
/// User class names for the input, separated by space
Expand Down Expand Up @@ -879,7 +880,6 @@ public async Task OpenMenu()

//disable escape propagation: if selectmenu is open, only the select popover should close and underlying components should not handle escape key
await _keyInterceptor.UpdateKey(new() { Key = "Escape", StopDown = "Key+none" });

await OnOpen.InvokeAsync();
}

Expand Down Expand Up @@ -966,9 +966,9 @@ public override async Task ForceUpdate()
}
}

public void BeginValidatePublic()
public async Task BeginValidatePublic()
{
BeginValidate();
await BeginValidateAsync();
}

protected internal bool Add(MudSelectItemExtended<T> item)
Expand Down Expand Up @@ -1108,7 +1108,12 @@ protected override bool HasValue(T value)

protected async Task ChipClosed(MudChip chip)
{
SelectedValues = SelectedValues.Where(x => Converter.Set(x)?.ToString() != chip.Value?.ToString());
if (chip == null || SelectedValues == null)
{
return;
}
//SelectedValues = SelectedValues.Where(x => Converter.Set(x)?.ToString() != chip.Value?.ToString());
SelectedValues = SelectedValues.Where(x => x.Equals(chip.Value) == false);
await SelectedValuesChanged.InvokeAsync(SelectedValues);
}
}
Expand Down
Loading