diff --git a/components/core/Component/Overlay/OverlayTrigger.razor.cs b/components/core/Component/Overlay/OverlayTrigger.razor.cs index 19443154..3378b3f2 100644 --- a/components/core/Component/Overlay/OverlayTrigger.razor.cs +++ b/components/core/Component/Overlay/OverlayTrigger.razor.cs @@ -423,7 +423,7 @@ namespace AntDesign.Internal /// /// MouseEventArgs /// - public virtual async Task OnClickDiv(MouseEventArgs args) + protected virtual async Task OnClickDiv(MouseEventArgs args) { if (!IsButton) { @@ -479,6 +479,10 @@ namespace AntDesign.Internal } } + /// + /// on document mouse up + /// + /// protected virtual void OnMouseUp(JsonElement element) { if (_mouseUpInOverlay) @@ -491,10 +495,10 @@ namespace AntDesign.Internal { if (OnMaskClick.HasDelegate) { - OnMaskClick.InvokeAsync(null); + _ = OnMaskClick.InvokeAsync(null); } - Hide(); + _ = Hide(); } } diff --git a/components/core/JsInterop/DomEventListener.cs b/components/core/JsInterop/DomEventListener.cs index 368029ec..64fda72c 100644 --- a/components/core/JsInterop/DomEventListener.cs +++ b/components/core/JsInterop/DomEventListener.cs @@ -38,7 +38,7 @@ namespace AntDesign.JsInterop return new DomEventKey(selector, eventName, _id); } - public void AddExclusive(object dom, string eventName, Action callback, bool preventDefault = false) + public void AddExclusive(object dom, string eventName, Action callback, bool preventDefault = false, bool stopPropagation = false) { var key = FormatKey(dom, eventName); if (_exclusiveDotNetObjectStore.ContainsKey(key)) @@ -48,7 +48,7 @@ namespace AntDesign.JsInterop { callback(p); })); - _jsRuntime.InvokeAsync(JSInteropConstants.AddDomEventListener, dom, eventName, preventDefault, dotNetObject); + _jsRuntime.InvokeAsync(JSInteropConstants.AddDomEventListener, dom, eventName, preventDefault, dotNetObject, stopPropagation); _exclusiveDotNetObjectStore.Add(key, dotNetObject); } diff --git a/components/core/JsInterop/IDomEventListener.cs b/components/core/JsInterop/IDomEventListener.cs index ea2e887e..1adf5d13 100644 --- a/components/core/JsInterop/IDomEventListener.cs +++ b/components/core/JsInterop/IDomEventListener.cs @@ -13,7 +13,7 @@ namespace AntDesign.JsInterop void AddEventListenerToFirstChild(object dom, string eventName, Action callback, bool preventDefault = false); - void AddExclusive(object dom, string eventName, Action callback, bool preventDefault = false); + void AddExclusive(object dom, string eventName, Action callback, bool preventDefault = false, bool stopPropagation = false); ValueTask AddResizeObserver(ElementReference dom, Action> callback); diff --git a/components/core/JsInterop/modules/dom/eventHelper.ts b/components/core/JsInterop/modules/dom/eventHelper.ts index 3494081c..c72cac65 100644 --- a/components/core/JsInterop/modules/dom/eventHelper.ts +++ b/components/core/JsInterop/modules/dom/eventHelper.ts @@ -10,7 +10,7 @@ export class eventHelper { return element.dispatchEvent(evt); } - static addDomEventListener(element, eventName: string, preventDefault: boolean, invoker: any) { + static addDomEventListener(element, eventName: string, preventDefault: boolean, invoker: any, stopPropagation: boolean = false) { const callback = args => { const obj = {}; for (let k in args) { @@ -28,6 +28,9 @@ export class eventHelper { if (preventDefault === true) { args.preventDefault(); } + if (stopPropagation) { + args.stopPropagation(); + } }; const dom = domInfoHelper.get(element); diff --git a/components/dropdown/Dropdown.razor.cs b/components/dropdown/Dropdown.razor.cs index b8eb0741..91d3aea1 100644 --- a/components/dropdown/Dropdown.razor.cs +++ b/components/dropdown/Dropdown.razor.cs @@ -110,7 +110,7 @@ namespace AntDesign /// /// MouseEventArgs /// - public override async Task OnClickDiv(MouseEventArgs args) + protected override async Task OnClickDiv(MouseEventArgs args) { if (!IsButton) { diff --git a/components/select/Select.razor b/components/select/Select.razor index 340563db..70c5ba25 100644 --- a/components/select/Select.razor +++ b/components/select/Select.razor @@ -7,7 +7,6 @@ -
- -
diff --git a/components/select/Select.razor.cs b/components/select/Select.razor.cs index 5fc95757..aea93ded 100644 --- a/components/select/Select.razor.cs +++ b/components/select/Select.razor.cs @@ -791,7 +791,7 @@ namespace AntDesign protected async Task SetDropdownStyleAsync() { string maxWidth = "", minWidth = "", definedWidth = ""; - var domRect = await JsInvokeAsync(JSInteropConstants.GetBoundingClientRect, Ref); + var domRect = await JsInvokeAsync(JSInteropConstants.GetBoundingClientRect, _selectContent.Ref); var width = domRect.Width.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture); minWidth = $"min-width: {width}px;"; if (DropdownMatchSelectWidth.IsT0 && DropdownMatchSelectWidth.AsT0) diff --git a/components/select/SelectBase.cs b/components/select/SelectBase.cs index 22ae34d7..4ae1ecd3 100644 --- a/components/select/SelectBase.cs +++ b/components/select/SelectBase.cs @@ -59,6 +59,8 @@ namespace AntDesign internal RenderFragment FeedbackIcon => FormItem?.FeedbackIcon; + internal ClassMapper CurrentClassMapper => ClassMapper; + /// /// Overlay adjustment strategy (when for example browser resize is happening) /// @@ -981,7 +983,7 @@ namespace AntDesign /// Check if Focused property is False; Set the Focused property to true, change the /// style and set the Focus on the Input element via DOM. It also invoke the OnFocus Action. /// - protected async Task SetInputFocusAsync() + internal async Task SetInputFocusAsync() { if (!Focused) { @@ -1004,11 +1006,6 @@ namespace AntDesign } } - internal async Task OnArrowClick(MouseEventArgs args) - { - await _dropDown.OnClickDiv(args); - } - /// /// Close the overlay /// diff --git a/components/select/internal/SelectContent.razor b/components/select/internal/SelectContent.razor index 08c2b46b..dc97e8f8 100644 --- a/components/select/internal/SelectContent.razor +++ b/components/select/internal/SelectContent.razor @@ -1,218 +1,33 @@ @using AntDesign +@using System.Text.Json +@using AntDesign.JsInterop @namespace AntDesign.Select.Internal @typeparam TItemValue @typeparam TItem @inherits AntDomComponentBase - -@if (ParentSelect.SelectMode == SelectMode.Default) -{ -
- @if (ParentSelect.PrefixIcon != null) +
+ @if (ParentSelect.SelectMode == SelectMode.Default) { - - } - - - - @if (ShowPlaceholder) - { - @Placeholder - } - else - { - var selectedItem = ParentSelect.SelectedOptionItems.FirstOrDefault(); - if (string.IsNullOrEmpty(SearchValue) && selectedItem != null) - { - @if (ParentLabelTemplate != null) +
+ @if (ParentSelect.PrefixIcon != null) { - - - @ParentLabelTemplate(selectedItem.Item) - - - } - else - { - - @getLabel(selectedItem) - - } - } - } -
- - -} -else //ParentSelect.SelectMode != SelectMode.Default -{ -
-
- @if (ParentSelect.PrefixIcon != null) - { -
-
- } - @if (!ShowPlaceholder) - { - var selectedItems = ParentSelect.SelectedOptionItems; - @if (ParentSelect.HasTagCount) - { - @for (int i = 0; i < Math.Min(ParentSelect.MaxTagCount.AsT0, selectedItems.Count); i++) - { - var selectedOption = selectedItems[i]; -
- @if (ParentLabelTemplate != null) - { - - - @ParentLabelTemplate(selectedOption.Item) - - - } - else - { - - @getTagLabel(this,selectedOption) - - - } -
- } - @if (selectedItems.Count > ParentSelect.MaxTagCount.AsT0) - { -
- @if (ParentMaxTagPlaceholerTemplate != null) - { - - @ParentMaxTagPlaceholerTemplate(selectedItems.Skip(ParentSelect.MaxTagCount.AsT0).Select(i => i.Item)) - - } - else - { - - - + @(selectedItems.Count - ParentSelect.MaxTagCount.AsT0)@Ellipse - - - } -
- } } - else if (ParentSelect.IsResponsive) - { - @for (int i = 0; i < selectedItems.Count; i++) - { - var selectedOption = selectedItems[i]; -
- @if (ParentLabelTemplate != null) - { - - - @ParentLabelTemplate(selectedOption.Item) - - - } - else - { - - @getTagLabel(this,selectedOption) - - - } -
- } - @if (selectedItems.Count > _calculatedMaxCount) - { -
- @if (ParentMaxTagPlaceholerTemplate != null) - { - - @ParentMaxTagPlaceholerTemplate(selectedItems.Skip(_calculatedMaxCount).Select(i => i.Item)) - - } - else - { - - + @(selectedItems.Count-_calculatedMaxCount)@Ellipse - - } -
- } - } - else - { - string firstAfterPrefix = $"max-width: {GetFirstItemMaxWidth()}%;"; - @foreach (var selectedOption in selectedItems) - { -
- @if (ParentLabelTemplate != null) - { - - - @ParentLabelTemplate(selectedOption.Item) - - - } - else - { - - @getTagLabel(this,selectedOption) - - - } -
- firstAfterPrefix = "max-width: 98%;"; - } - } - } -
- + + + } + else //ParentSelect.SelectMode != SelectMode.Default + { +
+
+ @if (ParentSelect.PrefixIcon != null) + { +
+ +
+ } + @if (!ShowPlaceholder) + { + var selectedItems = ParentSelect.SelectedOptionItems; + @if (ParentSelect.HasTagCount) + { + @for (int i = 0; i < Math.Min(ParentSelect.MaxTagCount.AsT0, selectedItems.Count); i++) + { + var selectedOption = selectedItems[i]; +
+ @if (ParentLabelTemplate != null) + { + + + @ParentLabelTemplate(selectedOption.Item) + + + } + else + { + + @getTagLabel(this,selectedOption) + + + } +
+ } + @if (selectedItems.Count > ParentSelect.MaxTagCount.AsT0) + { +
+ @if (ParentMaxTagPlaceholerTemplate != null) + { + + @ParentMaxTagPlaceholerTemplate(selectedItems.Skip(ParentSelect.MaxTagCount.AsT0).Select(i => i.Item)) + + } + else + { + + + + @(selectedItems.Count - ParentSelect.MaxTagCount.AsT0)@Ellipse + + + } +
+ } + } + else if (ParentSelect.IsResponsive) + { + @for (int i = 0; i < selectedItems.Count; i++) + { + var selectedOption = selectedItems[i]; +
+ @if (ParentLabelTemplate != null) + { + + + @ParentLabelTemplate(selectedOption.Item) + + + } + else + { + + @getTagLabel(this,selectedOption) + + + } +
+ } + @if (selectedItems.Count > _calculatedMaxCount) + { +
+ @if (ParentMaxTagPlaceholerTemplate != null) + { + + @ParentMaxTagPlaceholerTemplate(selectedItems.Skip(_calculatedMaxCount).Select(i => i.Item)) + + } + else + { + + + @(selectedItems.Count-_calculatedMaxCount)@Ellipse + + } +
+ } + } + else + { + string firstAfterPrefix = $"max-width: {GetFirstItemMaxWidth()}%;"; + @foreach (var selectedOption in selectedItems) + { +
+ @if (ParentLabelTemplate != null) + { + + + @ParentLabelTemplate(selectedOption.Item) + + + } + else + { + + @getTagLabel(this,selectedOption) + + + } +
+ firstAfterPrefix = "max-width: 98%;"; + } + } + } +
+ +
+ @if (ShowPlaceholder) + { + @Placeholder + }
- @if (ShowPlaceholder) - { - @Placeholder - } -
-
- - -} + + + } +
@code { RenderFragment getLabel(SelectOptionItem option) => diff --git a/components/select/internal/SelectContent.razor.cs b/components/select/internal/SelectContent.razor.cs index 9cc7125e..849d1007 100644 --- a/components/select/internal/SelectContent.razor.cs +++ b/components/select/internal/SelectContent.razor.cs @@ -423,11 +423,6 @@ namespace AntDesign.Select.Internal } } - private async Task OnClearClickAsync(MouseEventArgs args) - { - await OnClearClick.InvokeAsync(args); - } - private async Task RemoveClicked(MouseEventArgs e, SelectOptionItem selectedOption) { if (e.Button == 0) diff --git a/components/select/internal/SelectSuffixIcon.razor b/components/select/internal/SelectSuffixIcon.razor index 1dd96c54..2873b9e0 100644 --- a/components/select/internal/SelectSuffixIcon.razor +++ b/components/select/internal/SelectSuffixIcon.razor @@ -4,7 +4,7 @@ @if (ParentSelect.SuffixIcon != null) { -