fix(module: select): new tag item label and value fix (#1121)

* fix(module:select): new tag item label and value fix

* fix: interop firefox "Permission Denied" fix

* fix(module:select): prefixIcon styling and positioning
This commit is contained in:
Andrzej Bakun 2021-02-14 10:42:44 +01:00 committed by GitHub
parent 954461119e
commit d98c851c70
4 changed files with 130 additions and 119 deletions

View File

@ -156,10 +156,12 @@ export function getBoundingClientRect(element) {
export function addDomEventListener(element, eventName, preventDefault, invoker) {
let callback = args => {
const obj = {};
for (let k in args) {
obj[k] = args[k];
}
let json = JSON.stringify(obj, (k, v) => {
for (let k in args) {
if (k !== 'originalTarget') { //firefox occasionally raises Permission Denied when this property is being stringified
obj[k] = args[k];
}
}
let json = JSON.stringify(obj, (k, v) => {
if (v instanceof Node) return 'Node';
if (v instanceof Window) return 'Window';
return v;
@ -177,7 +179,7 @@ export function addDomEventListener(element, eventName, preventDefault, invoker)
window.addEventListener(eventName, callback);
}
} else {
let dom = getDom(element);
let dom = getDom(element);
(dom as HTMLElement).addEventListener(eventName, callback);
}
}

View File

@ -1391,6 +1391,15 @@ namespace AntDesign
{
CustomTagSelectOptionItem.Label = searchValue;
CustomTagSelectOptionItem.Value = value;
if (_isPrimitive)
{
CustomTagSelectOptionItem.Item = (TItem)TypeDescriptor.GetConverter(typeof(TItem)).ConvertFromInvariantString(_searchValue);
}
else
{
typeof(TItem).GetProperty(LabelName).SetValue(CustomTagSelectOptionItem.Item, _searchValue);
typeof(TItem).GetProperty(ValueName).SetValue(CustomTagSelectOptionItem.Item, value);
}
}
}
}

View File

@ -2,131 +2,123 @@
@namespace AntDesign.Select.Internal
@typeparam TItemValue
@typeparam TItem
<div class="@Prefix-selector" @ref="@Ref" style="@(ParentSelect.PrefixIcon is null?"":"padding-left: 4px;")">
@if (ShowPlaceholder)
@{
bool showPrefixAsSeparate = false;
bool showPrefixInSelected = false;
if (ParentSelect.PrefixIcon != null)
{
@if (@ParentSelect.PrefixIcon != null)
{
<span>
<span class="@Prefix-prefix" unselectable="on" aria-hidden="true" style="user-select: none;" >
@ParentSelect.PrefixIcon
</span>
<span class="@Prefix-selection-placeholder" style="position: relative; left: 0px;">@Placeholder</span>
</span>
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;" >
@ParentSelect.PrefixIcon
</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
{
<span class="@Prefix-selection-placeholder">@Placeholder</span>
}
@if (ParentSelect.SelectMode == SelectMode.Default)
{
var selectedItem = ParentSelect.SelectedOptionItems.FirstOrDefault();
}
else
{
@if (ParentSelect.SelectMode == SelectMode.Default)
{
var selectedItem = ParentSelect.SelectedOptionItems.FirstOrDefault();
if (string.IsNullOrEmpty(SearchValue) && selectedItem != null)
{
@if (ParentLabelTemplate != null)
if (string.IsNullOrEmpty(SearchValue) && selectedItem != null)
{
<CascadingValue Value="this" Name="SelectContent">
<CascadingValue Value="@selectedItem" Name="SelectOption">
@if (@ParentSelect.PrefixIcon != null)
{
<span>
<span class="@Prefix-prefix" unselectable="on" aria-hidden="true" style="user-select: none;" >
@ParentSelect.PrefixIcon
</span>
@ParentLabelTemplate(selectedItem.Item)
</span>
}
else
{
@ParentLabelTemplate(selectedItem.Item)
}
</CascadingValue>
</CascadingValue>
}
else
{
@if (@ParentSelect.PrefixIcon != null)
{
<span>
<span class="@Prefix-prefix" unselectable="on" aria-hidden="true" style="user-select: none;" >
@ParentSelect.PrefixIcon
</span>
<span class="@Prefix-selection-item">
<span class="@Prefix-selection-item-content">@selectedItem.Label</span>
</span>
</span>
}
else
@if (ParentLabelTemplate != null)
{
<CascadingValue Value="this" Name="SelectContent">
<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>
}
}
}
}
else
{
var selectedItems = ParentSelect.SelectedOptionItems;
@foreach (var selectedOption in selectedItems)
else
{
@if (ParentLabelTemplate != null)
var selectedItems = ParentSelect.SelectedOptionItems;
@if (showPrefixInSelected)
{
<CascadingValue Value="this" Name="SelectContent">
<CascadingValue Value="@selectedOption" Name="SelectOption">
@ParentLabelTemplate(selectedOption.Item)
</CascadingValue>
</CascadingValue>
}
else
<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)
{
<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">
<Icon Type="close"></Icon>
</span>
</span>
@if (ParentLabelTemplate != null)
{
<CascadingValue Value="this" Name="SelectContent">
<CascadingValue Value="@selectedOption" Name="SelectOption">
@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">
<Icon Type="close"></Icon>
</span>
</span>
}
}
}
}
}
<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"/>
<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"/>
@if (ParentSelect.SelectMode != SelectMode.Default)
{
<span class="@Prefix-selection-search-mirror" aria-hidden="true">&nbsp;</span>
}
</span>
@if (ParentSelect.SelectMode != SelectMode.Default)
{
<span class="@Prefix-selection-search-mirror" aria-hidden="true">&nbsp;</span>
}
</span>
</div>
</div>
@if (ParentSelect.SelectMode == SelectMode.Default)

View File

@ -65,27 +65,35 @@ namespace AntDesign.Select.Internal
protected override Task OnParametersSetAsync()
{
if (ParentSelect.SelectMode != SelectMode.Default) // ToDo Fix class
SetInputWidth();
SetInputWidth(); // ToDo Fix class
return base.OnParametersSetAsync();
}
private void SetInputWidth()
{
if (!string.IsNullOrWhiteSpace(SearchValue))
if (ParentSelect.PrefixIcon != null || ParentSelect.SelectMode == SelectMode.Default)
_inputWidth = "left: 0px;";
if (ParentSelect.SelectMode != SelectMode.Default)
{
_inputWidth = $"width: {4 + SearchValue.Length * 8}px;";
}
else
{
if (ParentSelect.HasValue)
if (!string.IsNullOrWhiteSpace(SearchValue))
{
_inputWidth = "width: 4px;"; //ToDo fix class
_inputWidth = $"{_inputWidth}width: {4 + SearchValue.Length * 8}px;";
}
else
{
_inputWidth = "width: 4px; margin-left: 6.5px;"; //ToDo fix class
if (ParentSelect.HasValue)
{
_inputWidth = $"{_inputWidth}width: 4px;"; //ToDo fix class
}
else if (ParentSelect.PrefixIcon != null)
{
_inputWidth = $"{_inputWidth}width: 4px; margin-left: 0px;"; //ToDo fix class
}
else
{
_inputWidth = $"{_inputWidth}width: 4px; margin-left: 10px;"; //ToDo fix class
}
}
}
}