fix(module: select): load icon for multiple mode & value reload on delay (#1307)

* chore: add GitHub Actions for auto preview (#1205)

* chore: add github actions for auto preview

* fix setup job

* chore: add GitHub Actions for auto preview (#1205)

* fix(module:select): add loading for multiple mode

* fix(module:select): selected items duplication for multiple mode when values changed outside the component

Co-authored-by: James Yeung <shunjiey@hotmail.com>
This commit is contained in:
Andrzej Bakun 2021-04-03 19:53:25 +02:00 committed by GitHub
parent 194caa37fb
commit 251a6e18ad
3 changed files with 83 additions and 40 deletions

View File

@ -111,7 +111,7 @@
</div>
</Overlay>
<Unbound>
<CascadingValue Value="this" Name=@("ParentSelect") IsFixed="true">
<CascadingValue Value="this" Name=@("ParentSelect") IsFixed>
<CascadingValue Value="@LabelTemplate" Name="ParentLabelTemplate">
<CascadingValue Value="@ShowSearchIcon" Name="ShowSearchIcon">
<CascadingValue Value="@ShowArrowIcon" Name="ShowArrowIcon">

View File

@ -163,7 +163,7 @@ namespace AntDesign
else
{
SelectOptionItems.Clear();
SelectedOptionItems.Clear();
Value = default;
_datasource = null;
@ -176,6 +176,7 @@ namespace AntDesign
if (value != null && !value.Any() && SelectOptionItems.Any())
{
SelectOptionItems.Clear();
SelectedOptionItems.Clear();
Value = default;
@ -538,6 +539,8 @@ namespace AntDesign
if (exists is null)
{
SelectOptionItems.Remove(selectOption);
if (selectOption.IsSelected)
SelectedOptionItems.Remove(selectOption);
}
else
dataStoreToSelectOptionItemsMatch.Add(exists, selectOption);
@ -545,6 +548,14 @@ namespace AntDesign
}
}
//A simple approach to avoid unnecessary scanning through _selectedValues once
//all of SelectOptionItem where already marked as selected
int processedSelectedCount = 0;
if (SelectMode == SelectMode.Default && _selectedValue != null)
processedSelectedCount = 1;
else if (SelectMode != SelectMode.Default && _selectedValues != null)
processedSelectedCount = _selectedValues.Count();
foreach (var item in _datasource)
{
TItemValue value = _getValue(item);
@ -568,6 +579,15 @@ namespace AntDesign
var groupName = string.Empty;
var label = _getLabel(item);
bool isSelected = false;
if (processedSelectedCount > 0)
{
if (SelectMode == SelectMode.Default)
isSelected = value.Equals(_selectedValue);
else
isSelected = _selectedValues.Contains(value);
}
if (!string.IsNullOrWhiteSpace(DisabledName))
disabled = _getDisabled(item);
@ -582,16 +602,33 @@ namespace AntDesign
GroupName = groupName,
IsDisabled = disabled,
Item = item,
Value = value
Value = value,
IsSelected = isSelected,
IsHidden = isSelected && HideSelected
};
SelectOptionItems.Add(newItem);
if (isSelected)
{
processedSelectedCount--;
SelectedOptionItems.Add(newItem);
}
}
else if (exists && !IgnoreItemChanges)
{
updateSelectOption.Label = label;
updateSelectOption.IsDisabled = disabled;
updateSelectOption.GroupName = groupName;
updateSelectOption.IsHidden = isSelected && HideSelected;
if (isSelected)
{
if (!updateSelectOption.IsSelected)
{
updateSelectOption.IsSelected = isSelected;
SelectedOptionItems.Add(updateSelectOption);
}
processedSelectedCount--;
}
}
}
}

View File

@ -5,38 +5,38 @@
@{
bool showPrefixAsSeparate = false;
bool showPrefixInSelected = false;
if (ParentSelect.PrefixIcon != null)
{
showPrefixAsSeparate = ParentSelect.PrefixIcon != null && !(ParentSelect.SelectMode != SelectMode.Default && ParentSelect.SelectedOptionItems.Any());
showPrefixInSelected = !showPrefixAsSeparate;
}
}
}
<div class="@Prefix-selector" @ref="@Ref" style="@(ParentSelect.PrefixIcon is null?"":"padding-left: 4px;")">
@if (showPrefixAsSeparate)
{
<span class="@Prefix-prefix" unselectable="on" aria-hidden="true" style="user-select: none;display:flex;align-items: center;padding-right: 4px;" >
<span class="@Prefix-prefix" unselectable="on" aria-hidden="true" style="user-select: none;display:flex;align-items: center;padding-right: 4px;">
@ParentSelect.PrefixIcon
</span>
</span>
}
<div style="display: flex;position: relative;flex-grow: 1;flex-wrap: wrap;align-items: center;">
@if (ShowPlaceholder)
{
{
@if (showPrefixAsSeparate)
{
<span class="@Prefix-selection-placeholder" style="left: 0px;">@Placeholder</span>
}
else
{
{
<span class="@Prefix-selection-placeholder">@Placeholder</span>
}
}
else
{
@if (ParentSelect.SelectMode == SelectMode.Default)
{
{
var selectedItem = ParentSelect.SelectedOptionItems.FirstOrDefault();
//Console.WriteLine($"({ParentSelect.Id}): {selectedItem.Value} => {selectedItem.Label}");
if (string.IsNullOrEmpty(SearchValue) && selectedItem != null)
@ -44,13 +44,13 @@
@if (ParentLabelTemplate != null)
{
<CascadingValue Value="this" Name="SelectContent">
<CascadingValue Value="@selectedItem" Name="SelectOption">
@ParentLabelTemplate(selectedItem.Item)
<CascadingValue Value="@selectedItem" Name="SelectOption">
@ParentLabelTemplate(selectedItem.Item)
</CascadingValue>
</CascadingValue>
}
else
{
{
<span class="@Prefix-selection-item">
<span class="@Prefix-selection-item-content">@selectedItem.Label</span>
</span>
@ -61,31 +61,31 @@
{
var selectedItems = ParentSelect.SelectedOptionItems;
@if (showPrefixInSelected)
@if (showPrefixInSelected)
{
<span class="@Prefix-prefix" unselectable="on" aria-hidden="true" style="user-select: none;display:flex;align-items: center;padding-right: 4px;" >
<span class="@Prefix-prefix" unselectable="on" aria-hidden="true" style="user-select: none;display:flex;align-items: center;padding-right: 4px;">
@ParentSelect.PrefixIcon
</span>
}
}
@foreach (var selectedOption in selectedItems)
{
@if (ParentLabelTemplate != null)
{
<CascadingValue Value="this" Name="SelectContent">
<CascadingValue Value="@selectedOption" Name="SelectOption">
@ParentLabelTemplate(selectedOption.Item)
</CascadingValue>
@ParentLabelTemplate(selectedOption.Item)
</CascadingValue>
</CascadingValue>
}
else
{
<span class="@Prefix-selection-item">
<span class="@Prefix-selection-item-content">@selectedOption.Label</span>
<span unselectable="on" aria-hidden="true" style="user-select: none;" class="@Prefix-selection-item-remove"
@onclick="()=> OnRemoveSelected.InvokeAsync(selectedOption)" @onclick:stopPropagation="true">
@onclick="()=> OnRemoveSelected.InvokeAsync(selectedOption)" @onclick:stopPropagation="true">
<Icon Type="close"></Icon>
</span>
</span>
</span>
}
}
}
@ -93,25 +93,25 @@
<span class="@Prefix-selection-search" style="@_inputWidth">
<input @ref="ParentSelect._inputRef"
@oninput="OnInput"
@onkeyup="OnKeyUp"
@onkeydown="OnKeyDown"
@onfocus="OnFocus"
@onblur="OnBlur"
@attributes=@AdditonalAttributes()
@onkeypress="@OnKeyPressEventHandler"
@onkeypress:preventDefault="@_suppressInput"
@onkeypress:stopPropagation="true"
@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"
style="@_inputStyle"/>
@oninput="OnInput"
@onkeyup="OnKeyUp"
@onkeydown="OnKeyDown"
@onfocus="OnFocus"
@onblur="OnBlur"
@attributes=@AdditonalAttributes()
@onkeypress="@OnKeyPressEventHandler"
@onkeypress:preventDefault="@_suppressInput"
@onkeypress:stopPropagation="true"
@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"
style="@_inputStyle"/>
@if (ParentSelect.SelectMode != SelectMode.Default)
{
@ -165,7 +165,7 @@
}
</span>
}
@if (!ParentSelect.Disabled && ParentSelect.AllowClear && ParentSelect.HasValue)
{
<span class="ant-select-clear" unselectable="on" aria-hidden="true" style="user-select: none;" @onclick="OnClearClick" @onclick:stopPropagation="true">
@ -182,6 +182,12 @@ else
@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>
}
@if (!ParentSelect.Disabled && ParentSelect.AllowClear && ParentSelect.HasValue)
{
<span class="ant-select-clear" unselectable="on" aria-hidden="true" style="user-select: none;" @onclick="OnClearClick" @onclick:stopPropagation="true">