2020-06-27 18:24:21 +08:00
|
|
|
|
using System;
|
2020-09-09 00:52:14 +08:00
|
|
|
|
using System.Collections;
|
2020-06-27 18:24:21 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-09-09 00:52:14 +08:00
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Diagnostics;
|
2020-06-27 18:24:21 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using AntDesign.JsInterop;
|
2020-09-09 00:52:14 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
2020-06-27 18:24:21 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
2020-08-26 22:37:08 +08:00
|
|
|
|
using OneOf;
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
2020-11-02 23:05:17 +08:00
|
|
|
|
public partial class AutoComplete<TOption> : AntInputComponentBase<string>, IAutoCompleteRef
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-08-26 22:37:08 +08:00
|
|
|
|
#region Parameters
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-10-09 16:32:40 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string Placeholder { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Disabled { get; set; }
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public bool DefaultActiveFirstOption { get; set; } = true;
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Backfill { get; set; } = false;
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-11-02 23:05:17 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 列表对象集合
|
|
|
|
|
/// </summary>
|
|
|
|
|
private List<AutoCompleteOption> AutoCompleteOptions { get; set; } = new List<AutoCompleteOption>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 列表数据集合
|
|
|
|
|
/// </summary>
|
|
|
|
|
private List<AutoCompleteDataItem<TOption>> _optionDataItems = new List<AutoCompleteDataItem<TOption>>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 列表绑定数据源集合
|
|
|
|
|
/// </summary>
|
|
|
|
|
private IEnumerable<TOption> _options;
|
|
|
|
|
[Parameter]
|
|
|
|
|
public IEnumerable<TOption> Options
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _options;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_options = value;
|
|
|
|
|
_optionDataItems = _options?.Select(x => new AutoCompleteDataItem<TOption>(x, x.ToString())).ToList() ?? new List<AutoCompleteDataItem<TOption>>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 绑定列表数据项格式的数据源
|
|
|
|
|
/// </summary>
|
2020-08-26 22:37:08 +08:00
|
|
|
|
[Parameter]
|
2020-11-02 23:05:17 +08:00
|
|
|
|
public IEnumerable<AutoCompleteDataItem<TOption>> OptionDataItems
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _optionDataItems;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_optionDataItems = value.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<AutoCompleteOption> OnSelectionChange { get; set; }
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<AutoCompleteOption> OnActiveChange { get; set; }
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<ChangeEventArgs> OnInput { get; set; }
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-10-09 16:32:40 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<bool> OnPanelVisibleChange { get; set; }
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-11-02 23:05:17 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 选项模板
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment<AutoCompleteDataItem<TOption>> OptionTemplate { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 格式化选项,可以自定义显示格式
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<AutoCompleteDataItem<TOption>, string> OptionFormat { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 所有选项模板
|
|
|
|
|
/// </summary>
|
2020-08-26 22:37:08 +08:00
|
|
|
|
[Parameter]
|
2020-11-02 23:05:17 +08:00
|
|
|
|
public RenderFragment OverlayTemplate { get; set; }
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-11-02 23:05:17 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 对比,用于两个对象比较是否相同
|
|
|
|
|
/// </summary>
|
2020-08-26 22:37:08 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<object, object, bool> CompareWith { get; set; } = (o1, o2) => o1?.ToString() == o2?.ToString();
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-11-02 23:05:17 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 过滤表达式
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<AutoCompleteDataItem<TOption>, string, bool> FilterExpression { get; set; } = (option, value) => string.IsNullOrEmpty(value) ? true : option.Label.Contains(value, StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 允许过滤
|
|
|
|
|
/// </summary>
|
2020-08-26 22:37:08 +08:00
|
|
|
|
[Parameter]
|
2020-11-02 23:05:17 +08:00
|
|
|
|
public bool AllowFilter { get; set; } = true;
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<int?, string> Width { get; set; }
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string OverlayClassName { get; set; }
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string OverlayStyle { get; set; }
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-09-17 10:37:47 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string PopupContainerSelector { get; set; } = "body";
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
#endregion Parameters
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
private ElementReference _divRef;
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-11-02 23:05:17 +08:00
|
|
|
|
public object SelectedValue { get; set; }
|
2020-06-27 18:24:21 +08:00
|
|
|
|
/// <summary>
|
2020-08-26 22:37:08 +08:00
|
|
|
|
/// 选择的项
|
2020-06-27 18:24:21 +08:00
|
|
|
|
/// </summary>
|
2020-08-26 22:37:08 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public AutoCompleteOption SelectedItem { get; set; }
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-08-26 22:37:08 +08:00
|
|
|
|
/// 高亮的项目
|
2020-06-27 18:24:21 +08:00
|
|
|
|
/// </summary>
|
2020-11-02 23:05:17 +08:00
|
|
|
|
public object ActiveValue { get; set; }
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public bool ShowPanel { get; set; } = false;
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
private bool _isOptionsZero = true;
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
private IAutoCompleteInput _inputComponent;
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
public void SetInputComponent(IAutoCompleteInput input)
|
2020-07-31 12:43:46 +08:00
|
|
|
|
{
|
2020-08-26 22:37:08 +08:00
|
|
|
|
_inputComponent = input;
|
2020-07-31 12:43:46 +08:00
|
|
|
|
}
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
#region 子控件触发事件
|
|
|
|
|
public async Task InputFocus(FocusEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.OpenPanel();
|
|
|
|
|
}
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
public async Task InputInput(ChangeEventArgs args)
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-11-02 23:05:17 +08:00
|
|
|
|
SelectedValue = args?.Value;
|
2020-08-26 22:37:08 +08:00
|
|
|
|
if (OnInput.HasDelegate) await OnInput.InvokeAsync(args);
|
|
|
|
|
StateHasChanged();
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
public async Task InputKeyDown(KeyboardEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var key = args.Key;
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
if (this.ShowPanel)
|
|
|
|
|
{
|
|
|
|
|
if (key == "Escape" || key == "Tab")
|
|
|
|
|
{
|
|
|
|
|
this.ClosePanel();
|
|
|
|
|
}
|
|
|
|
|
else if (key == "Enter" && this.ActiveValue != null)
|
|
|
|
|
{
|
|
|
|
|
await SetSelectedItem(GetActiveItem());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.OpenPanel();
|
|
|
|
|
}
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
if (key == "ArrowUp")
|
|
|
|
|
{
|
|
|
|
|
this.SetPreviousItemActive();
|
|
|
|
|
}
|
|
|
|
|
else if (key == "ArrowDown")
|
2020-07-31 12:43:46 +08:00
|
|
|
|
{
|
2020-08-26 22:37:08 +08:00
|
|
|
|
this.SetNextItemActive();
|
2020-07-31 12:43:46 +08:00
|
|
|
|
}
|
2020-08-26 22:37:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
base.OnParametersSet();
|
|
|
|
|
ResetActiveItem();
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
protected override async Task OnFirstAfterRenderAsync()
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-08-26 22:37:08 +08:00
|
|
|
|
await SetOverlayWidth();
|
|
|
|
|
await base.OnFirstAfterRenderAsync();
|
|
|
|
|
}
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-11-02 23:05:17 +08:00
|
|
|
|
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
public void AddOption(AutoCompleteOption option)
|
|
|
|
|
{
|
2020-11-02 23:05:17 +08:00
|
|
|
|
AutoCompleteOptions.Add(option);
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
public void RemoveOption(AutoCompleteOption option)
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-11-02 23:05:17 +08:00
|
|
|
|
if (AutoCompleteOptions?.Contains(option) == true)
|
|
|
|
|
AutoCompleteOptions?.Remove(option);
|
2020-08-26 22:37:08 +08:00
|
|
|
|
}
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-11-02 23:05:17 +08:00
|
|
|
|
public IList<AutoCompleteDataItem<TOption>> GetOptionItems()
|
2020-08-26 22:37:08 +08:00
|
|
|
|
{
|
2020-11-02 23:05:17 +08:00
|
|
|
|
if (_optionDataItems != null)
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-11-02 23:05:17 +08:00
|
|
|
|
if (FilterExpression != null && AllowFilter == true && SelectedValue != null)
|
|
|
|
|
return _optionDataItems.Where(x => FilterExpression(x, SelectedValue?.ToString())).ToList();
|
2020-08-26 22:37:08 +08:00
|
|
|
|
else
|
2020-11-02 23:05:17 +08:00
|
|
|
|
return _optionDataItems;
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
2020-08-26 22:37:08 +08:00
|
|
|
|
else
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-11-02 23:05:17 +08:00
|
|
|
|
return new List<AutoCompleteDataItem<TOption>>();
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打开面板
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void OpenPanel()
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-08-26 22:37:08 +08:00
|
|
|
|
if (this.ShowPanel == false)
|
|
|
|
|
{
|
|
|
|
|
this.ShowPanel = true;
|
|
|
|
|
ResetActiveItem();
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭面板
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ClosePanel()
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-08-26 22:37:08 +08:00
|
|
|
|
if (this.ShowPanel == true)
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-08-26 22:37:08 +08:00
|
|
|
|
this.ShowPanel = false;
|
|
|
|
|
StateHasChanged();
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
2020-08-26 22:37:08 +08:00
|
|
|
|
}
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
public AutoCompleteOption GetActiveItem()
|
|
|
|
|
{
|
2020-11-02 23:05:17 +08:00
|
|
|
|
return AutoCompleteOptions.FirstOrDefault(x => CompareWith(x.Value, this.ActiveValue));
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
//设置高亮的对象
|
|
|
|
|
public void SetActiveItem(AutoCompleteOption item)
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-11-02 23:05:17 +08:00
|
|
|
|
this.ActiveValue = item == null ? default(TOption) : item.Value;
|
2020-08-26 22:37:08 +08:00
|
|
|
|
if (OnActiveChange.HasDelegate) OnActiveChange.InvokeAsync(item);
|
|
|
|
|
StateHasChanged();
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
//设置下一个激活
|
|
|
|
|
public void SetNextItemActive()
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-11-02 23:05:17 +08:00
|
|
|
|
var opts = AutoCompleteOptions.Where(x => x.Disabled == false).ToList();
|
2020-08-26 22:37:08 +08:00
|
|
|
|
var nextItem = opts.IndexOf(GetActiveItem());
|
|
|
|
|
if (nextItem == -1 || nextItem == opts.Count - 1)
|
|
|
|
|
SetActiveItem(opts.FirstOrDefault());
|
|
|
|
|
else
|
|
|
|
|
SetActiveItem(opts[nextItem + 1]);
|
|
|
|
|
|
|
|
|
|
if (Backfill)
|
|
|
|
|
_inputComponent.SetValue(this.ActiveValue);
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
//设置上一个激活
|
|
|
|
|
public void SetPreviousItemActive()
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-11-02 23:05:17 +08:00
|
|
|
|
var opts = AutoCompleteOptions.Where(x => x.Disabled == false).ToList();
|
2020-08-26 22:37:08 +08:00
|
|
|
|
var nextItem = opts.IndexOf(GetActiveItem());
|
|
|
|
|
if (nextItem == -1 || nextItem == 0)
|
|
|
|
|
SetActiveItem(opts.LastOrDefault());
|
|
|
|
|
else
|
|
|
|
|
SetActiveItem(opts[nextItem - 1]);
|
|
|
|
|
|
|
|
|
|
if (Backfill)
|
|
|
|
|
_inputComponent.SetValue(this.ActiveValue);
|
|
|
|
|
}
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
private void ResetActiveItem()
|
|
|
|
|
{
|
|
|
|
|
var items = GetOptionItems();
|
2020-11-02 23:05:17 +08:00
|
|
|
|
_isOptionsZero = items.Count == 0 && Options != null;
|
2020-08-26 22:37:08 +08:00
|
|
|
|
if (items.Any(x => CompareWith(x.Value, this.ActiveValue)) == false)
|
|
|
|
|
{//如果当前激活项找在列表中不存在,那么我们需要做一些处理
|
|
|
|
|
if (items.Any(x => CompareWith(x.Value, this.SelectedValue)))
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-08-26 22:37:08 +08:00
|
|
|
|
this.ActiveValue = this.SelectedValue;
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
2020-08-26 22:37:08 +08:00
|
|
|
|
else if (DefaultActiveFirstOption == true && items.Count > 0)
|
2020-07-31 12:43:46 +08:00
|
|
|
|
{
|
2020-11-02 23:05:17 +08:00
|
|
|
|
this.ActiveValue = items.FirstOrDefault().Value;
|
2020-07-31 12:43:46 +08:00
|
|
|
|
}
|
2020-08-26 22:37:08 +08:00
|
|
|
|
else
|
2020-07-31 12:43:46 +08:00
|
|
|
|
{
|
2020-08-26 22:37:08 +08:00
|
|
|
|
this.ActiveValue = null;
|
2020-07-31 12:43:46 +08:00
|
|
|
|
}
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
public async Task SetSelectedItem(AutoCompleteOption item)
|
|
|
|
|
{
|
|
|
|
|
if (item != null)
|
|
|
|
|
{
|
2020-11-02 23:05:17 +08:00
|
|
|
|
this.SelectedValue = item.Value;
|
2020-08-26 22:37:08 +08:00
|
|
|
|
this.SelectedItem = item;
|
|
|
|
|
_inputComponent?.SetValue(this.SelectedItem.Label);
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
if (OnSelectionChange.HasDelegate) await OnSelectionChange.InvokeAsync(this.SelectedItem);
|
|
|
|
|
}
|
|
|
|
|
this.ClosePanel();
|
|
|
|
|
}
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-10-09 16:32:40 +08:00
|
|
|
|
bool _parPanelVisible = false;
|
|
|
|
|
|
|
|
|
|
private async void OnOverlayTriggerVisibleChange(bool visible)
|
2020-09-27 23:05:23 +08:00
|
|
|
|
{
|
2020-10-09 16:32:40 +08:00
|
|
|
|
if (OnPanelVisibleChange.HasDelegate && _parPanelVisible != visible)
|
|
|
|
|
{
|
|
|
|
|
_parPanelVisible = visible;
|
|
|
|
|
await OnPanelVisibleChange.InvokeAsync(visible);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.ShowPanel != visible)
|
|
|
|
|
{
|
|
|
|
|
this.ShowPanel = visible;
|
|
|
|
|
}
|
2020-09-27 23:05:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
private string _minWidth = "";
|
|
|
|
|
private async Task SetOverlayWidth()
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-08-26 22:37:08 +08:00
|
|
|
|
string newWidth;
|
|
|
|
|
if (Width.Value != null)
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-08-26 22:37:08 +08:00
|
|
|
|
var w = Width.Match<string>(f0 => $"{f0}px", f1 => f1);
|
|
|
|
|
newWidth = $"min-width:{w}";
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
2020-08-26 22:37:08 +08:00
|
|
|
|
else
|
2020-06-27 18:24:21 +08:00
|
|
|
|
{
|
2020-09-09 00:52:14 +08:00
|
|
|
|
Element element = await JsInvokeAsync<Element>(JSInteropConstants.GetDomInfo, _divRef);
|
2020-08-26 22:37:08 +08:00
|
|
|
|
newWidth = $"min-width:{element.clientWidth}px";
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
2020-08-26 22:37:08 +08:00
|
|
|
|
if (newWidth != _minWidth) _minWidth = newWidth;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-11-02 23:05:17 +08:00
|
|
|
|
public class AutoCompleteDataItem<TOption>
|
2020-08-26 22:37:08 +08:00
|
|
|
|
{
|
|
|
|
|
public AutoCompleteDataItem() { }
|
2020-06-27 18:24:21 +08:00
|
|
|
|
|
2020-11-02 23:05:17 +08:00
|
|
|
|
public AutoCompleteDataItem(TOption value, string label)
|
2020-08-26 22:37:08 +08:00
|
|
|
|
{
|
|
|
|
|
Value = value;
|
|
|
|
|
Label = label;
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-02 23:05:17 +08:00
|
|
|
|
public TOption Value { get; set; }
|
2020-08-26 22:37:08 +08:00
|
|
|
|
public string Label { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool IsDisabled { get; set; }
|
2020-06-27 18:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-26 22:37:08 +08:00
|
|
|
|
|