2021-02-04 23:40:47 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text.Json;
|
2020-11-27 13:13:26 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2021-04-15 14:19:26 +08:00
|
|
|
|
using AntDesign.Core.Extensions;
|
2021-04-27 14:03:39 +08:00
|
|
|
|
using AntDesign.Core.JsInterop.ObservableApi;
|
2021-02-04 23:40:47 +08:00
|
|
|
|
using AntDesign.JsInterop;
|
2020-11-27 13:13:26 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
2021-02-04 23:40:47 +08:00
|
|
|
|
using Microsoft.JSInterop;
|
2020-11-27 13:13:26 +08:00
|
|
|
|
|
|
|
|
|
#pragma warning disable 1591 // Disable missing XML comment
|
|
|
|
|
|
|
|
|
|
namespace AntDesign.Select.Internal
|
|
|
|
|
{
|
2021-02-04 23:40:47 +08:00
|
|
|
|
public partial class SelectContent<TItemValue, TItem>: IDisposable
|
2020-11-27 13:13:26 +08:00
|
|
|
|
{
|
|
|
|
|
[CascadingParameter(Name = "ParentSelect")] internal Select<TItemValue, TItem> ParentSelect { get; set; }
|
|
|
|
|
[CascadingParameter(Name = "ParentLabelTemplate")] internal RenderFragment<TItem> ParentLabelTemplate { get; set; }
|
2021-04-13 13:12:18 +08:00
|
|
|
|
[CascadingParameter(Name = "ParentMaxTagPlaceholerTemplate")] internal RenderFragment<IEnumerable<TItem>> ParentMaxTagPlaceholerTemplate { get; set; }
|
2020-11-27 13:13:26 +08:00
|
|
|
|
[CascadingParameter(Name = "ShowSearchIcon")] internal bool ShowSearchIcon { get; set; }
|
|
|
|
|
[CascadingParameter(Name = "ShowArrowIcon")] internal bool ShowArrowIcon { get; set; }
|
2021-04-08 22:17:44 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string Prefix
|
|
|
|
|
{
|
|
|
|
|
get { return _prefix; }
|
|
|
|
|
set {
|
|
|
|
|
_prefix = value;
|
|
|
|
|
if (_isInitialized)
|
|
|
|
|
SetInputWidth();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-27 13:13:26 +08:00
|
|
|
|
[Parameter] public string Placeholder { get; set; }
|
|
|
|
|
[Parameter] public bool IsOverlayShow { get; set; }
|
|
|
|
|
[Parameter] public bool ShowPlaceholder { get; set; }
|
|
|
|
|
[Parameter] public EventCallback<ChangeEventArgs> OnInput { get; set; }
|
|
|
|
|
[Parameter] public EventCallback<KeyboardEventArgs> OnKeyUp { get; set; }
|
|
|
|
|
[Parameter] public EventCallback<KeyboardEventArgs> OnKeyDown { get; set; }
|
|
|
|
|
[Parameter] public EventCallback<FocusEventArgs> OnFocus { get; set; }
|
|
|
|
|
[Parameter] public EventCallback<FocusEventArgs> OnBlur { get; set; }
|
|
|
|
|
[Parameter] public EventCallback<MouseEventArgs> OnClearClick { get; set; }
|
|
|
|
|
[Parameter] public EventCallback<SelectOptionItem<TItemValue, TItem>> OnRemoveSelected { get; set; }
|
|
|
|
|
[Parameter] public string SearchValue { get; set; }
|
2021-01-21 17:20:10 +08:00
|
|
|
|
[Parameter] public ForwardRef RefBack { get; set; } = new ForwardRef();
|
2021-02-04 23:40:47 +08:00
|
|
|
|
[Inject] protected IJSRuntime Js { get; set; }
|
|
|
|
|
[Inject] private DomEventService DomEventService { get; set; }
|
2021-01-21 17:20:10 +08:00
|
|
|
|
protected ElementReference Ref
|
|
|
|
|
{
|
|
|
|
|
get { return _ref; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_ref = value;
|
|
|
|
|
RefBack?.Set(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-27 13:13:26 +08:00
|
|
|
|
|
2021-04-13 13:12:18 +08:00
|
|
|
|
private const char Ellipse = (char)0x2026;
|
|
|
|
|
private const int ItemMargin = 4; //taken from each tag item
|
2020-11-27 13:13:26 +08:00
|
|
|
|
private string _inputStyle = string.Empty;
|
|
|
|
|
private string _inputWidth;
|
|
|
|
|
private bool _suppressInput;
|
2021-04-08 22:17:44 +08:00
|
|
|
|
private bool _isInitialized;
|
|
|
|
|
private string _prefix;
|
2021-04-13 13:12:18 +08:00
|
|
|
|
private int _calculatedMaxCount;
|
|
|
|
|
private int _lastInputWidth;
|
|
|
|
|
|
|
|
|
|
private ElementReference _ref;
|
|
|
|
|
private ElementReference _overflow;
|
|
|
|
|
private ElementReference _aggregateTag;
|
|
|
|
|
private ElementReference _prefixRef;
|
|
|
|
|
private ElementReference _suffixRef;
|
|
|
|
|
private DomRect _overflowElement;
|
|
|
|
|
private DomRect _aggregateTagElement;
|
|
|
|
|
private DomRect _prefixElement = new();
|
|
|
|
|
private DomRect _suffixElement = new();
|
|
|
|
|
private int _currentItemCount;
|
|
|
|
|
private Guid _internalId = Guid.NewGuid();
|
|
|
|
|
private bool _refocus;
|
2020-11-27 13:13:26 +08:00
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
2021-04-08 22:17:44 +08:00
|
|
|
|
if (!_isInitialized)
|
2021-04-13 13:12:18 +08:00
|
|
|
|
{
|
2021-04-08 22:17:44 +08:00
|
|
|
|
SetInputWidth();
|
2021-04-13 13:12:18 +08:00
|
|
|
|
}
|
2021-04-08 22:17:44 +08:00
|
|
|
|
_isInitialized = true;
|
2020-11-27 13:13:26 +08:00
|
|
|
|
SetSuppressInput();
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-04 23:40:47 +08:00
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
2020-11-27 13:13:26 +08:00
|
|
|
|
{
|
|
|
|
|
SetSuppressInput();
|
2021-04-13 13:12:18 +08:00
|
|
|
|
if (firstRender)
|
2021-02-04 23:40:47 +08:00
|
|
|
|
{
|
2021-04-13 13:12:18 +08:00
|
|
|
|
if (ParentSelect.EnableSearch)
|
|
|
|
|
{
|
|
|
|
|
DomEventService.AddEventListener("window", "beforeunload", Reloading, false);
|
|
|
|
|
await Js.InvokeVoidAsync(JSInteropConstants.AddPreventKeys, ParentSelect._inputRef, new[] { "ArrowUp", "ArrowDown" });
|
|
|
|
|
await Js.InvokeVoidAsync(JSInteropConstants.AddPreventEnterOnOverlayVisible, ParentSelect._inputRef, ParentSelect.DropDownRef);
|
|
|
|
|
}
|
|
|
|
|
if (ParentSelect.IsResponsive)
|
|
|
|
|
{
|
|
|
|
|
_currentItemCount = ParentSelect.SelectedOptionItems.Count;
|
2021-04-15 14:19:26 +08:00
|
|
|
|
//even though it is run in OnAfterRender, it may happen that the browser
|
|
|
|
|
//did not manage to render yet the element; force a continuous check
|
|
|
|
|
//until the element gets the id
|
|
|
|
|
while (_aggregateTag.Id is null)
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_aggregateTagElement = await Js.InvokeAsync<DomRect>(JSInteropConstants.GetBoundingClientRect, _aggregateTag, _aggregateTag.Id, true);
|
2021-04-13 13:12:18 +08:00
|
|
|
|
|
|
|
|
|
if (_prefixRef.Id != default)
|
|
|
|
|
{
|
|
|
|
|
_prefixElement = await Js.InvokeAsync<DomRect>(JSInteropConstants.GetBoundingClientRect, _prefixRef);
|
2021-04-17 22:14:01 +08:00
|
|
|
|
_prefixElement.Width += ItemMargin;
|
2021-04-13 13:12:18 +08:00
|
|
|
|
}
|
|
|
|
|
if (_suffixRef.Id != default)
|
|
|
|
|
{
|
|
|
|
|
_suffixElement = await Js.InvokeAsync<DomRect>(JSInteropConstants.GetBoundingClientRect, _suffixRef);
|
2021-04-17 22:14:01 +08:00
|
|
|
|
_suffixElement.Width += 7;
|
2021-04-13 13:12:18 +08:00
|
|
|
|
}
|
2021-04-27 14:03:39 +08:00
|
|
|
|
await DomEventService.AddResizeObserver(_overflow, OnOveralyResize);
|
2021-04-13 13:12:18 +08:00
|
|
|
|
await CalculateResponsiveTags();
|
|
|
|
|
}
|
2021-04-15 14:19:26 +08:00
|
|
|
|
DomEventService.AddEventListener(ParentSelect._inputRef, "focusout", OnBlurInternal, true);
|
|
|
|
|
DomEventService.AddEventListener(ParentSelect._inputRef, "focus", OnFocusInternal, true);
|
2021-04-13 13:12:18 +08:00
|
|
|
|
}
|
|
|
|
|
else if (_currentItemCount != ParentSelect.SelectedOptionItems.Count)
|
|
|
|
|
{
|
|
|
|
|
_currentItemCount = ParentSelect.SelectedOptionItems.Count;
|
|
|
|
|
_aggregateTagElement = await Js.InvokeAsync<DomRect>(JSInteropConstants.GetBoundingClientRect, _aggregateTag);
|
|
|
|
|
await CalculateResponsiveTags(_refocus);
|
2021-02-04 23:40:47 +08:00
|
|
|
|
}
|
|
|
|
|
await base.OnAfterRenderAsync(firstRender);
|
2020-11-27 13:13:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 14:03:39 +08:00
|
|
|
|
protected async void OnOveralyResize(List<ResizeObserverEntry> entries)
|
2021-04-13 13:12:18 +08:00
|
|
|
|
{
|
2021-04-27 14:03:39 +08:00
|
|
|
|
await CalculateResponsiveTags(false, entries[0].ContentRect);
|
2021-04-13 13:12:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 14:03:39 +08:00
|
|
|
|
internal async Task CalculateResponsiveTags(bool forceInputFocus = false, DomRect entry = null)
|
2021-04-13 13:12:18 +08:00
|
|
|
|
{
|
2021-04-15 14:19:26 +08:00
|
|
|
|
if (!ParentSelect.IsResponsive)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-04-27 14:03:39 +08:00
|
|
|
|
if (entry is null)
|
|
|
|
|
_overflowElement = await Js.InvokeAsync<DomRect>(JSInteropConstants.GetBoundingClientRect, _overflow);
|
|
|
|
|
else
|
|
|
|
|
_overflowElement = entry;
|
2021-04-13 13:12:18 +08:00
|
|
|
|
|
|
|
|
|
//distance between items is margin-inline-left=4px
|
2021-04-17 22:14:01 +08:00
|
|
|
|
decimal accumulatedWidth = _prefixElement.Width + _suffixElement.Width + (4 + (SearchValue?.Length ?? 0) * 8);
|
2021-04-13 13:12:18 +08:00
|
|
|
|
int i = 0;
|
|
|
|
|
bool overflowing = false;
|
|
|
|
|
bool renderAgain = false;
|
|
|
|
|
foreach (var item in ParentSelect.SelectedOptionItems)
|
|
|
|
|
{
|
|
|
|
|
if (item.Width == 0)
|
|
|
|
|
{
|
|
|
|
|
var itemElement = await Js.InvokeAsync<DomRect>(JSInteropConstants.GetBoundingClientRect, item.SelectedTagRef);
|
2021-04-17 22:14:01 +08:00
|
|
|
|
item.Width = itemElement.Width;
|
2021-04-13 13:12:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!overflowing)
|
|
|
|
|
{
|
2021-04-17 22:14:01 +08:00
|
|
|
|
if (accumulatedWidth + item.Width > _overflowElement.Width)
|
2021-04-13 13:12:18 +08:00
|
|
|
|
{
|
|
|
|
|
//current item will overflow; check if with aggregateTag will overflow
|
2021-04-17 22:14:01 +08:00
|
|
|
|
if (accumulatedWidth + _aggregateTagElement.Width > _overflowElement.Width)
|
2021-04-13 13:12:18 +08:00
|
|
|
|
{
|
|
|
|
|
if (_calculatedMaxCount != Math.Max(0, i - 1))
|
|
|
|
|
{
|
|
|
|
|
_calculatedMaxCount = Math.Max(0, i - 1);
|
|
|
|
|
renderAgain = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else //aggregateTag will not overflow, so start aggregating from current item
|
|
|
|
|
{
|
|
|
|
|
if (_calculatedMaxCount != i)
|
|
|
|
|
{
|
|
|
|
|
_calculatedMaxCount = i;
|
|
|
|
|
renderAgain = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
overflowing = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
accumulatedWidth += item.Width;
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!overflowing && _calculatedMaxCount != i)
|
|
|
|
|
{
|
|
|
|
|
_calculatedMaxCount = i;
|
|
|
|
|
renderAgain = true;
|
|
|
|
|
}
|
|
|
|
|
if (renderAgain)
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
|
|
|
|
|
//force focus on cursor
|
|
|
|
|
if (ParentSelect.IsDropdownShown() || forceInputFocus)
|
|
|
|
|
{
|
|
|
|
|
var isFocused = await Js.InvokeAsync<bool>(JSInteropConstants.HasFocus, ParentSelect._inputRef);
|
|
|
|
|
if (!isFocused)
|
|
|
|
|
{
|
2021-04-15 14:19:26 +08:00
|
|
|
|
await Js.FocusAsync(ParentSelect._inputRef);
|
2021-04-13 13:12:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-27 13:13:26 +08:00
|
|
|
|
private void SetInputWidth()
|
|
|
|
|
{
|
2021-04-08 22:17:44 +08:00
|
|
|
|
_inputWidth = string.Empty;
|
|
|
|
|
if (ParentSelect.PrefixIcon != null && ParentSelect.SelectMode == SelectMode.Default)
|
|
|
|
|
{
|
|
|
|
|
_inputWidth = "left: 22px;";
|
|
|
|
|
}
|
2021-02-14 17:42:44 +08:00
|
|
|
|
if (ParentSelect.SelectMode != SelectMode.Default)
|
2020-11-27 13:13:26 +08:00
|
|
|
|
{
|
2021-02-14 17:42:44 +08:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(SearchValue))
|
2020-11-27 13:13:26 +08:00
|
|
|
|
{
|
2021-02-14 17:42:44 +08:00
|
|
|
|
_inputWidth = $"{_inputWidth}width: {4 + SearchValue.Length * 8}px;";
|
2021-04-13 13:12:18 +08:00
|
|
|
|
if (ParentSelect.IsResponsive && _lastInputWidth != SearchValue.Length)
|
|
|
|
|
{
|
|
|
|
|
_lastInputWidth = SearchValue.Length;
|
|
|
|
|
InvokeAsync(async() => await CalculateResponsiveTags());
|
|
|
|
|
}
|
2020-11-27 13:13:26 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-02-14 17:42:44 +08:00
|
|
|
|
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
|
|
|
|
|
}
|
2020-11-27 13:13:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetSuppressInput()
|
|
|
|
|
{
|
|
|
|
|
if (!ParentSelect.IsSearchEnabled)
|
|
|
|
|
{
|
|
|
|
|
if (!_suppressInput)
|
|
|
|
|
{
|
|
|
|
|
_suppressInput = true;
|
|
|
|
|
_inputStyle = "caret-color: transparent;";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (_suppressInput)
|
|
|
|
|
{
|
|
|
|
|
_suppressInput = false;
|
|
|
|
|
_inputStyle = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 13:12:18 +08:00
|
|
|
|
private string OverflowStyle(int order)
|
|
|
|
|
{
|
|
|
|
|
string width = "max-width: 98%;";
|
|
|
|
|
if (order == 0)
|
|
|
|
|
width = $"max-width: {GetFirstItemMaxWidth()}%;";
|
|
|
|
|
if (ParentSelect.HasTagCount || ParentSelect.IsResponsive)
|
|
|
|
|
{
|
|
|
|
|
if (_calculatedMaxCount < order + 1)
|
|
|
|
|
{
|
|
|
|
|
return $"opacity: 0.2; order: {order}; height: 0px; overflow-y: hidden; pointer-events: none; {width}";
|
|
|
|
|
}
|
|
|
|
|
return $"opacity: 1; order: {order}; {width}";
|
|
|
|
|
}
|
|
|
|
|
return "opacity: 1;" + width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string FormatLabel(string label)
|
|
|
|
|
{
|
|
|
|
|
if (ParentSelect.MaxTagTextLength > 0)
|
|
|
|
|
{
|
|
|
|
|
return label.Length <= ParentSelect.MaxTagTextLength ? label : label.Substring(0, ParentSelect.MaxTagTextLength) + Ellipse;
|
|
|
|
|
}
|
|
|
|
|
return label;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-27 13:13:26 +08:00
|
|
|
|
protected void OnKeyPressEventHandler(KeyboardEventArgs _)
|
|
|
|
|
{
|
|
|
|
|
if (!ParentSelect.IsSearchEnabled)
|
|
|
|
|
SearchValue = string.Empty;
|
2021-04-13 13:12:18 +08:00
|
|
|
|
else if (ParentSelect.IsResponsive)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2020-11-27 13:13:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Dictionary<string, object> AdditonalAttributes()
|
|
|
|
|
{
|
|
|
|
|
var dict = new Dictionary<string, object>();
|
|
|
|
|
|
|
|
|
|
if (ParentSelect.Disabled)
|
|
|
|
|
dict.Add("tabindex", "-1");
|
|
|
|
|
|
|
|
|
|
return dict;
|
|
|
|
|
}
|
2021-02-04 23:40:47 +08:00
|
|
|
|
|
2021-04-08 22:17:44 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Any item may overflow. In case of first item, when there
|
|
|
|
|
/// are any other elements inside SelectContent (prefix, suffix, clear btn, etc)
|
|
|
|
|
/// default MaxWidth will force th SelectContent to grow. Changing the MaxWidth
|
|
|
|
|
/// allows the overflowing item to fit in a single line.
|
|
|
|
|
/// TODO: use relative units
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private int GetFirstItemMaxWidth()
|
|
|
|
|
{
|
|
|
|
|
int percentValue = 98;
|
|
|
|
|
if (ParentSelect.PrefixIcon != null)
|
|
|
|
|
{
|
|
|
|
|
if (ShowArrowIcon || ShowSearchIcon)
|
|
|
|
|
{
|
|
|
|
|
if (ParentSelect.AllowClear)
|
|
|
|
|
{
|
|
|
|
|
percentValue = 90;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
percentValue = 93;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
percentValue = 94;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ShowArrowIcon || ShowSearchIcon)
|
|
|
|
|
{
|
|
|
|
|
if (ParentSelect.AllowClear)
|
|
|
|
|
{
|
|
|
|
|
percentValue = 94;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
percentValue = 96;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return percentValue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-04 23:40:47 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates that a page is being refreshed
|
|
|
|
|
/// </summary>
|
2021-04-13 13:12:18 +08:00
|
|
|
|
private bool _isReloading;
|
2021-02-04 23:40:47 +08:00
|
|
|
|
|
|
|
|
|
private void Reloading(JsonElement jsonElement) => _isReloading = true;
|
|
|
|
|
|
2021-04-13 13:12:18 +08:00
|
|
|
|
internal async Task RemovedItem()
|
|
|
|
|
{
|
|
|
|
|
if (ParentSelect.IsResponsive)
|
|
|
|
|
{
|
|
|
|
|
_refocus = true;
|
|
|
|
|
await CalculateResponsiveTags();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OnClearClickAsync(MouseEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
await OnClearClick.InvokeAsync(args);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-23 22:48:14 +08:00
|
|
|
|
private async Task RemoveClicked(MouseEventArgs e, SelectOptionItem<TItemValue, TItem> selectedOption)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button == 0)
|
|
|
|
|
{
|
|
|
|
|
await OnRemoveSelected.InvokeAsync(selectedOption);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-15 14:19:26 +08:00
|
|
|
|
//TODO: Use built in @onfocus once https://github.com/dotnet/aspnetcore/issues/30070 is solved
|
|
|
|
|
private async void OnFocusInternal(JsonElement e) => await OnFocus.InvokeAsync(new());
|
|
|
|
|
|
|
|
|
|
//TODO: Use built in @onblur once https://github.com/dotnet/aspnetcore/issues/30070 is solved
|
|
|
|
|
private async void OnBlurInternal(JsonElement e) => await OnBlur.InvokeAsync(new());
|
|
|
|
|
|
|
|
|
|
|
2021-02-04 23:40:47 +08:00
|
|
|
|
public bool IsDisposed { get; private set; }
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (!_isReloading)
|
|
|
|
|
{
|
|
|
|
|
_ = InvokeAsync(async () =>
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(100);
|
2021-04-27 14:03:39 +08:00
|
|
|
|
if (ParentSelect.IsResponsive)
|
|
|
|
|
await DomEventService.DisposeResizeObserver(_overflow);
|
2021-03-04 23:16:24 +08:00
|
|
|
|
await Js.InvokeVoidAsync(JSInteropConstants.RemovePreventKeys, ParentSelect._inputRef);
|
2021-04-13 13:12:18 +08:00
|
|
|
|
await Js.InvokeVoidAsync(JSInteropConstants.RemovePreventEnterOnOverlayVisible, ParentSelect._inputRef);
|
2021-02-04 23:40:47 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2021-04-15 14:19:26 +08:00
|
|
|
|
DomEventService.RemoveEventListerner<JsonElement>(ParentSelect._inputRef, "focus", OnFocusInternal);
|
|
|
|
|
DomEventService.RemoveEventListerner<JsonElement>(ParentSelect._inputRef, "focusout", OnBlurInternal);
|
2021-02-04 23:40:47 +08:00
|
|
|
|
DomEventService.RemoveEventListerner<JsonElement>("window", "beforeunload", Reloading);
|
|
|
|
|
|
|
|
|
|
if (IsDisposed) return;
|
|
|
|
|
|
|
|
|
|
IsDisposed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~SelectContent()
|
|
|
|
|
{
|
|
|
|
|
// Finalizer calls Dispose(false)
|
|
|
|
|
Dispose(false);
|
|
|
|
|
}
|
2020-11-27 13:13:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|