diff --git a/components/core/JsInterop/interop.ts b/components/core/JsInterop/interop.ts index 995282a6..c0dbaa74 100644 --- a/components/core/JsInterop/interop.ts +++ b/components/core/JsInterop/interop.ts @@ -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); } } diff --git a/components/select/Select.razor.cs b/components/select/Select.razor.cs index 9d813548..34db9f66 100644 --- a/components/select/Select.razor.cs +++ b/components/select/Select.razor.cs @@ -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); + } } } } diff --git a/components/select/internal/SelectContent.razor b/components/select/internal/SelectContent.razor index 13fb9f53..c8e7c052 100644 --- a/components/select/internal/SelectContent.razor +++ b/components/select/internal/SelectContent.razor @@ -2,131 +2,123 @@ @namespace AntDesign.Select.Internal @typeparam TItemValue @typeparam TItem - -
- @if (ShowPlaceholder) +@{ + bool showPrefixAsSeparate = false; + bool showPrefixInSelected = false; + + if (ParentSelect.PrefixIcon != null) { - @if (@ParentSelect.PrefixIcon != null) - { - - - @Placeholder - + showPrefixAsSeparate = ParentSelect.PrefixIcon != null && !(ParentSelect.SelectMode != SelectMode.Default && ParentSelect.SelectedOptionItems.Any()); + showPrefixInSelected = !showPrefixAsSeparate; + } +} + + +
+ @if (showPrefixAsSeparate) + { + + } +
+ @if (ShowPlaceholder) + { + @if (showPrefixAsSeparate) + { + @Placeholder + } + else + { + @Placeholder + } } else { - - @Placeholder - } + @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) { - - - @if (@ParentSelect.PrefixIcon != null) - { - - - @ParentLabelTemplate(selectedItem.Item) - - } - else - { - @ParentLabelTemplate(selectedItem.Item) - } - - - } - else - { - @if (@ParentSelect.PrefixIcon != null) - { - - - - @selectedItem.Label - - - } - else + @if (ParentLabelTemplate != null) { + + + @ParentLabelTemplate(selectedItem.Item) + + + } + else + { @selectedItem.Label } } } - } - else - { - var selectedItems = ParentSelect.SelectedOptionItems; - - @foreach (var selectedOption in selectedItems) + else { - @if (ParentLabelTemplate != null) + var selectedItems = ParentSelect.SelectedOptionItems; + + @if (showPrefixInSelected) { - - - @ParentLabelTemplate(selectedOption.Item) - - - } - else + + } + @foreach (var selectedOption in selectedItems) { - - @selectedOption.Label - - + @if (ParentLabelTemplate != null) + { + + + @ParentLabelTemplate(selectedOption.Item) + + + } + else + { + + @selectedOption.Label + + + } } } } - } - - + + - @if (ParentSelect.SelectMode != SelectMode.Default) - { - - } - + @if (ParentSelect.SelectMode != SelectMode.Default) + { + + } + +
@if (ParentSelect.SelectMode == SelectMode.Default) diff --git a/components/select/internal/SelectContent.razor.cs b/components/select/internal/SelectContent.razor.cs index 4db171dd..918868d7 100644 --- a/components/select/internal/SelectContent.razor.cs +++ b/components/select/internal/SelectContent.razor.cs @@ -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 + } } } }