2020-09-09 22:12:12 +08:00
|
|
|
|
@namespace AntDesign.Internal
|
2020-09-19 09:15:16 +08:00
|
|
|
|
@inherits AntDomComponentBase
|
2020-09-09 22:12:12 +08:00
|
|
|
|
@using OneOf;
|
|
|
|
|
|
|
|
|
|
@switch (ParentSelect.SelectMode)
|
|
|
|
|
{
|
|
|
|
|
case SelectMode.Default:
|
|
|
|
|
{
|
|
|
|
|
var selectedOption = ParentSelect.SelectedOptions.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
<div class="@Prefix-selector">
|
|
|
|
|
<span class="@Prefix-selection-search">
|
|
|
|
|
<input @ref="ParentSelect._inputRef"
|
|
|
|
|
@oninput="OnInput"
|
|
|
|
|
id="@ParentSelect.Id"
|
|
|
|
|
value="@SearchValue"
|
|
|
|
|
role="combobox"
|
|
|
|
|
class="@Prefix-selection-search-input"
|
|
|
|
|
autocomplete="off"
|
|
|
|
|
aria-owns="@(ParentSelect.Id)_list"
|
|
|
|
|
aria-expanded="@IsOverlayShow"
|
|
|
|
|
aria-autocomplete="list"
|
|
|
|
|
aria-controls="@(ParentSelect.Id)_list" />
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
@if (ShowPlaceholder)
|
|
|
|
|
{
|
|
|
|
|
<span class="ant-select-selection-placeholder">@Placeholder</span>
|
|
|
|
|
}
|
|
|
|
|
else if (string.IsNullOrEmpty(SearchValue) && selectedOption != null)
|
|
|
|
|
{
|
2020-10-25 14:59:10 +08:00
|
|
|
|
<span class="ant-select-selection-item">
|
|
|
|
|
@{
|
|
|
|
|
var showValue = GetOptionShowValue(selectedOption);
|
|
|
|
|
if (showValue.IsT0)
|
|
|
|
|
{
|
|
|
|
|
@showValue.AsT0
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
@showValue.AsT1
|
|
|
|
|
}
|
2020-09-09 22:12:12 +08:00
|
|
|
|
}
|
2020-10-25 14:59:10 +08:00
|
|
|
|
</span>
|
2020-09-09 22:12:12 +08:00
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
<div class="@Prefix-selector">
|
|
|
|
|
@foreach (var option in ParentSelect.SelectedOptions)
|
|
|
|
|
{
|
|
|
|
|
if (ParentSelect.TagRender != null)
|
|
|
|
|
{
|
2020-09-17 14:14:48 +08:00
|
|
|
|
<span @key="@option.Value">@ParentSelect.TagRender(GetProperties(option))</span>
|
2020-09-09 22:12:12 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<span class="@Prefix-selection-item">
|
|
|
|
|
<span class="@Prefix-selection-item-content">
|
2020-10-25 14:59:10 +08:00
|
|
|
|
@{
|
|
|
|
|
var showValue = GetOptionShowValue(option);
|
|
|
|
|
if (showValue.IsT0)
|
|
|
|
|
{
|
|
|
|
|
@showValue.AsT0
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
@showValue.AsT1
|
|
|
|
|
}
|
2020-09-09 22:12:12 +08:00
|
|
|
|
}
|
|
|
|
|
</span>
|
|
|
|
|
|
2020-09-17 14:14:48 +08:00
|
|
|
|
@if (ParentSelect.SelectMode == SelectMode.Tags || ParentSelect.SelectMode == SelectMode.Multiple)
|
2020-09-09 22:12:12 +08:00
|
|
|
|
{
|
|
|
|
|
<span unselectable="on" aria-hidden="true" style="user-select: none;" class="@Prefix-selection-item-remove"
|
|
|
|
|
@onclick="()=>OnRemoveSelected.InvokeAsync(option)" @onclick:stopPropagation="true">
|
|
|
|
|
<Icon Type="close"></Icon>
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class="@Prefix-selection-search" style="width:@InputWidth">
|
|
|
|
|
<input @ref="ParentSelect._inputRef"
|
|
|
|
|
@oninput="OnInput"
|
|
|
|
|
@onkeyup="OnKeyUp"
|
|
|
|
|
@bind-value="@SearchValue"
|
|
|
|
|
id="@ParentSelect.Id"
|
|
|
|
|
role="combobox"
|
|
|
|
|
class="@Prefix-selection-search-input"
|
|
|
|
|
autocomplete="off"
|
|
|
|
|
aria-owns="@(ParentSelect.Id)_list"
|
|
|
|
|
aria-expanded="@IsOverlayShow"
|
|
|
|
|
aria-autocomplete="list"
|
|
|
|
|
aria-controls="@(ParentSelect.Id)_list" />
|
|
|
|
|
|
|
|
|
|
<span class="@Prefix-selection-search-mirror" aria-hidden="true"> </span>
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
@if (ShowPlaceholder)
|
|
|
|
|
{
|
|
|
|
|
<span class="ant-select-selection-placeholder">@Placeholder</span>
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@if (ParentSelect.ShowArrow && ParentSelect.SelectMode == SelectMode.Default)
|
|
|
|
|
{
|
|
|
|
|
if (ParentSelect.SuffixIcon != null)
|
|
|
|
|
{
|
|
|
|
|
<span class="ant-select-arrow" unselectable="on" aria-hidden="true" style="user-select: none;">
|
|
|
|
|
@ParentSelect.SuffixIcon
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
else if (ParentSelect.Loading)
|
|
|
|
|
{
|
|
|
|
|
<span class="ant-select-arrow ant-select-arrow-loading" unselectable="on" aria-hidden="true" style="user-select: none;">
|
|
|
|
|
<Icon Type="loading"></Icon>
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<span class="ant-select-arrow" unselectable="on" aria-hidden="true" style="user-select: none;">
|
|
|
|
|
@if (ParentSelect.ShowSearch && IsOverlayShow)
|
|
|
|
|
{
|
|
|
|
|
<Icon Type="search"></Icon>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<Icon Type="down"></Icon>
|
|
|
|
|
}
|
|
|
|
|
</span>
|
|
|
|
|
@if (ParentSelect.AllowClear && ParentSelect.HasValue)
|
|
|
|
|
{
|
|
|
|
|
<span class="ant-select-clear" unselectable="on" aria-hidden="true" style="user-select: none;" @onclick="OnClearClick">
|
|
|
|
|
<Icon Type="close-circle"></Icon>
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-25 14:59:10 +08:00
|
|
|
|
else if (ParentSelect.SelectMode != SelectMode.Default)
|
|
|
|
|
{
|
|
|
|
|
@if (ParentSelect.AllowClear && ParentSelect.HasValue)
|
|
|
|
|
{
|
|
|
|
|
<span class="ant-select-clear" unselectable="on" aria-hidden="true" style="user-select: none;" @onclick="OnClearClick">
|
|
|
|
|
<Icon Type="close-circle"></Icon>
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-09 22:12:12 +08:00
|
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
{
|
|
|
|
|
[CascadingParameter(Name = "ParentSelect")]
|
|
|
|
|
public Select ParentSelect { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Prefix { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string SearchValue { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Placeholder { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string InputWidth { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool IsOverlayShow { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-09-19 09:15:16 +08:00
|
|
|
|
public bool ShowPlaceholder { get; set; }
|
2020-09-09 22:12:12 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-09-19 09:15:16 +08:00
|
|
|
|
public EventCallback<ChangeEventArgs> OnInput { get; set; }
|
2020-09-09 22:12:12 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-09-19 09:15:16 +08:00
|
|
|
|
public EventCallback<SelectOption> OnRemoveSelected { get; set; }
|
2020-09-09 22:12:12 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<SelectOption, OneOf<string, RenderFragment>> GetOptionShowValue { get; set; }
|
|
|
|
|
|
|
|
|
|
protected bool IsShowSearch()
|
|
|
|
|
{
|
|
|
|
|
if (ParentSelect.SelectMode == SelectMode.Default)
|
|
|
|
|
{
|
|
|
|
|
return ParentSelect.ShowSearch;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected async Task OnClearClick(MouseEventArgs _)
|
|
|
|
|
{
|
2020-10-25 14:59:10 +08:00
|
|
|
|
await ParentSelect.ResetStateAsync();
|
2020-09-09 22:12:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected async void OnKeyUp(KeyboardEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Code == "Enter")
|
|
|
|
|
{
|
|
|
|
|
await ParentSelect.TransSearchValueToTag();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Properties GetProperties(SelectOption option)
|
|
|
|
|
{
|
|
|
|
|
return new Properties
|
|
|
|
|
{
|
|
|
|
|
Closable = true,
|
|
|
|
|
Value = option.Value,
|
|
|
|
|
Label = option.Label,
|
2020-09-17 14:14:48 +08:00
|
|
|
|
OnClose = (e) => { OnRemoveSelected.InvokeAsync(option); }
|
2020-09-09 22:12:12 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|