2020-08-28 14:04:46 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using AntDesign.JsInterop;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
2020-03-23 09:31:08 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components.Rendering;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2020-06-27 01:20:52 +08:00
|
|
|
|
public class Input<TValue> : AntInputComponentBase<TValue>
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
|
|
|
|
protected const string PrefixCls = "ant-input";
|
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
private bool _allowClear;
|
|
|
|
|
protected string AffixWrapperClass { get; set; } = $"{PrefixCls}-affix-wrapper";
|
|
|
|
|
protected string GroupWrapperClass { get; set; } = $"{PrefixCls}-group-wrapper";
|
|
|
|
|
|
|
|
|
|
//protected string ClearIconClass { get; set; }
|
|
|
|
|
protected static readonly EventCallbackFactory CallbackFactory = new EventCallbackFactory();
|
|
|
|
|
|
2020-07-30 09:06:56 +08:00
|
|
|
|
protected virtual bool IgnoreOnChangeAndBlur { get; }
|
|
|
|
|
|
2020-11-01 22:38:43 +08:00
|
|
|
|
protected virtual bool EnableOnPressEnter => OnPressEnter.HasDelegate;
|
|
|
|
|
|
2020-08-28 14:04:46 +08:00
|
|
|
|
[Inject]
|
|
|
|
|
public DomEventService DomEventService { get; set; }
|
|
|
|
|
|
2020-03-26 10:45:35 +08:00
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public string Type { get; set; } = "text";
|
2020-03-26 10:45:35 +08:00
|
|
|
|
|
2020-03-23 09:31:08 +08:00
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public RenderFragment AddOnBefore { get; set; }
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public RenderFragment AddOnAfter { get; set; }
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public string Placeholder { get; set; }
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
2020-06-02 13:26:27 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public bool AutoFocus { get; set; }
|
|
|
|
|
|
2020-03-23 09:31:08 +08:00
|
|
|
|
[Parameter]
|
2020-06-27 01:20:52 +08:00
|
|
|
|
public TValue DefaultValue { get; set; }
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public int MaxLength { get; set; } = -1;
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public bool Disabled { get; set; }
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public bool AllowClear { get; set; }
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public RenderFragment Prefix { get; set; }
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public RenderFragment Suffix { get; set; }
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
2020-03-26 10:45:35 +08:00
|
|
|
|
[Parameter]
|
2020-04-23 17:13:56 +08:00
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-06-27 18:24:21 +08:00
|
|
|
|
public EventCallback<TValue> OnChange { get; set; }
|
2020-04-23 17:13:56 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<KeyboardEventArgs> OnPressEnter { get; set; }
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<KeyboardEventArgs> OnkeyUp { get; set; }
|
2020-08-28 14:04:46 +08:00
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<KeyboardEventArgs> OnkeyDown { get; set; }
|
|
|
|
|
|
2020-10-12 00:20:33 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<MouseEventArgs> OnMouseUp { get; set; }
|
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<ChangeEventArgs> OnInput { get; set; }
|
|
|
|
|
|
2020-06-02 13:26:27 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<FocusEventArgs> OnBlur { get; set; }
|
|
|
|
|
|
2020-06-27 01:20:52 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<FocusEventArgs> OnFocus { get; set; }
|
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
public Dictionary<string, object> Attributes { get; set; }
|
2020-03-26 10:45:35 +08:00
|
|
|
|
|
2020-07-30 09:06:56 +08:00
|
|
|
|
private TValue _inputValue;
|
2020-08-28 14:04:46 +08:00
|
|
|
|
private bool _compositionInputting = false;
|
2020-07-30 09:06:56 +08:00
|
|
|
|
|
2020-03-23 09:31:08 +08:00
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
|
2020-06-27 01:20:52 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(DefaultValue?.ToString()) && string.IsNullOrEmpty(Value?.ToString()))
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
Value = DefaultValue;
|
2020-03-23 09:31:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetClasses();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void SetClasses()
|
|
|
|
|
{
|
2020-07-28 11:15:41 +08:00
|
|
|
|
AffixWrapperClass = $"{PrefixCls}-affix-wrapper";
|
|
|
|
|
GroupWrapperClass = $"{PrefixCls}-group-wrapper";
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(Class))
|
|
|
|
|
{
|
|
|
|
|
AffixWrapperClass = string.Join(" ", Class, AffixWrapperClass);
|
|
|
|
|
ClassMapper.OriginalClass = "";
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-23 09:31:08 +08:00
|
|
|
|
ClassMapper.Clear()
|
2020-10-12 00:20:33 +08:00
|
|
|
|
.Add($"{PrefixCls}")
|
2020-05-20 12:57:16 +08:00
|
|
|
|
.If($"{PrefixCls}-lg", () => Size == InputSize.Large)
|
|
|
|
|
.If($"{PrefixCls}-sm", () => Size == InputSize.Small);
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
2020-06-27 01:20:52 +08:00
|
|
|
|
Attributes ??= new Dictionary<string, object>();
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
if (MaxLength >= 0)
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
2020-04-23 17:13:56 +08:00
|
|
|
|
Attributes?.Add("maxlength", MaxLength);
|
2020-03-23 09:31:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
if (Disabled)
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
|
|
|
|
// TODO: disable element
|
2020-04-24 18:32:50 +08:00
|
|
|
|
AffixWrapperClass = string.Join(" ", AffixWrapperClass, $"{PrefixCls}-affix-wrapper-disabled");
|
2020-03-23 09:31:08 +08:00
|
|
|
|
ClassMapper.Add($"{PrefixCls}-disabled");
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 17:13:56 +08:00
|
|
|
|
if (AllowClear)
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
|
|
|
|
_allowClear = true;
|
2020-04-24 18:32:50 +08:00
|
|
|
|
//ClearIconClass = $"{PrefixCls}-clear-icon";
|
2020-03-23 09:31:08 +08:00
|
|
|
|
ToggleClearBtn();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-20 12:57:16 +08:00
|
|
|
|
if (Size == InputSize.Large)
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
2020-04-24 18:32:50 +08:00
|
|
|
|
AffixWrapperClass = string.Join(" ", AffixWrapperClass, $"{PrefixCls}-affix-wrapper-lg");
|
|
|
|
|
GroupWrapperClass = string.Join(" ", GroupWrapperClass, $"{PrefixCls}-group-wrapper-lg");
|
2020-03-23 09:31:08 +08:00
|
|
|
|
}
|
2020-05-20 12:57:16 +08:00
|
|
|
|
else if (Size == InputSize.Small)
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
2020-04-24 18:32:50 +08:00
|
|
|
|
AffixWrapperClass = string.Join(" ", AffixWrapperClass, $"{PrefixCls}-affix-wrapper-sm");
|
|
|
|
|
GroupWrapperClass = string.Join(" ", GroupWrapperClass, $"{PrefixCls}-group-wrapper-sm");
|
2020-03-23 09:31:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
base.OnParametersSet();
|
|
|
|
|
|
|
|
|
|
SetClasses();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-02 13:26:27 +08:00
|
|
|
|
public async Task Focus()
|
|
|
|
|
{
|
2020-09-09 00:52:14 +08:00
|
|
|
|
await JsInvokeAsync(JSInteropConstants.Focus, Ref);
|
2020-06-02 13:26:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-07 12:44:10 +08:00
|
|
|
|
protected virtual async Task OnChangeAsync(ChangeEventArgs args)
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
2020-07-30 09:06:56 +08:00
|
|
|
|
if (CurrentValueAsString != args?.Value?.ToString())
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
2020-07-30 09:06:56 +08:00
|
|
|
|
if (OnChange.HasDelegate)
|
|
|
|
|
{
|
|
|
|
|
await OnChange.InvokeAsync(Value);
|
|
|
|
|
}
|
2020-03-23 09:31:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 09:06:56 +08:00
|
|
|
|
protected async Task OnKeyPressAsync(KeyboardEventArgs args)
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
2020-11-01 22:38:43 +08:00
|
|
|
|
if (args != null && args.Key == "Enter" && EnableOnPressEnter)
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
2020-11-01 22:38:43 +08:00
|
|
|
|
await ChangeValue();
|
2020-04-23 17:13:56 +08:00
|
|
|
|
await OnPressEnter.InvokeAsync(args);
|
2020-11-01 22:38:43 +08:00
|
|
|
|
await OnPressEnterAsync();
|
2020-03-23 09:31:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-01 22:38:43 +08:00
|
|
|
|
protected virtual Task OnPressEnterAsync() => Task.CompletedTask;
|
|
|
|
|
|
2020-07-30 09:06:56 +08:00
|
|
|
|
protected async Task OnKeyUpAsync(KeyboardEventArgs args)
|
|
|
|
|
{
|
2020-11-01 16:06:16 +08:00
|
|
|
|
await ChangeValue();
|
2020-08-26 22:37:08 +08:00
|
|
|
|
|
|
|
|
|
if (OnkeyUp.HasDelegate) await OnkeyUp.InvokeAsync(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual async Task OnkeyDownAsync(KeyboardEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (OnkeyDown.HasDelegate) await OnkeyDown.InvokeAsync(args);
|
2020-07-30 09:06:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 00:20:33 +08:00
|
|
|
|
protected async Task OnMouseUpAsync(MouseEventArgs args)
|
|
|
|
|
{
|
2020-11-01 16:06:16 +08:00
|
|
|
|
await ChangeValue();
|
2020-10-12 00:20:33 +08:00
|
|
|
|
|
|
|
|
|
if (OnMouseUp.HasDelegate) await OnMouseUp.InvokeAsync(args);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
internal virtual async Task OnBlurAsync(FocusEventArgs e)
|
2020-06-02 13:26:27 +08:00
|
|
|
|
{
|
2020-11-01 16:06:16 +08:00
|
|
|
|
if (_compositionInputting)
|
|
|
|
|
{
|
|
|
|
|
_compositionInputting = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await ChangeValue();
|
|
|
|
|
|
2020-06-02 13:26:27 +08:00
|
|
|
|
if (OnBlur.HasDelegate)
|
|
|
|
|
{
|
|
|
|
|
await OnBlur.InvokeAsync(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 22:37:08 +08:00
|
|
|
|
internal virtual async Task OnFocusAsync(FocusEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (OnFocus.HasDelegate)
|
|
|
|
|
{
|
|
|
|
|
await OnFocus.InvokeAsync(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-28 14:04:46 +08:00
|
|
|
|
|
|
|
|
|
internal virtual void OnCompositionStart(JsonElement e)
|
|
|
|
|
{
|
|
|
|
|
_compositionInputting = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal virtual void OnCompositionEnd(JsonElement e)
|
|
|
|
|
{
|
|
|
|
|
_compositionInputting = false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-23 09:31:08 +08:00
|
|
|
|
private void ToggleClearBtn()
|
|
|
|
|
{
|
2020-04-24 18:32:50 +08:00
|
|
|
|
Suffix = (builder) =>
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
2020-06-07 19:41:00 +08:00
|
|
|
|
builder.OpenComponent<Icon>(31);
|
2020-06-01 14:09:28 +08:00
|
|
|
|
builder.AddAttribute(32, "Type", "close-circle");
|
2020-07-30 09:06:56 +08:00
|
|
|
|
builder.AddAttribute(33, "Class", GetClearIconCls());
|
2020-07-12 00:28:10 +08:00
|
|
|
|
if (string.IsNullOrEmpty(Value?.ToString()))
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.AddAttribute(34, "Style", "visibility: hidden;");
|
2020-03-23 09:31:08 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.AddAttribute(34, "Style", "visibility: visible;");
|
2020-03-23 09:31:08 +08:00
|
|
|
|
}
|
2020-07-30 09:06:56 +08:00
|
|
|
|
builder.AddAttribute(35, "OnClick", CallbackFactory.Create<MouseEventArgs>(this, (args) =>
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
2020-07-12 00:28:10 +08:00
|
|
|
|
CurrentValue = default;
|
2020-06-29 00:26:11 +08:00
|
|
|
|
if (OnChange.HasDelegate)
|
|
|
|
|
OnChange.InvokeAsync(Value);
|
2020-03-23 09:31:08 +08:00
|
|
|
|
ToggleClearBtn();
|
|
|
|
|
}));
|
|
|
|
|
builder.CloseComponent();
|
2020-04-24 18:32:50 +08:00
|
|
|
|
};
|
2020-03-23 09:31:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-01 16:06:16 +08:00
|
|
|
|
private async Task ChangeValue()
|
|
|
|
|
{
|
|
|
|
|
if (!_compositionInputting)
|
|
|
|
|
{
|
|
|
|
|
if (!EqualityComparer<TValue>.Default.Equals(CurrentValue, _inputValue))
|
|
|
|
|
{
|
|
|
|
|
CurrentValue = _inputValue;
|
|
|
|
|
if (OnChange.HasDelegate)
|
|
|
|
|
{
|
|
|
|
|
await OnChange.InvokeAsync(Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-02 13:26:27 +08:00
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
|
|
|
|
await base.OnAfterRenderAsync(firstRender);
|
|
|
|
|
|
2020-08-28 14:04:46 +08:00
|
|
|
|
if (firstRender)
|
2020-06-02 13:26:27 +08:00
|
|
|
|
{
|
2020-08-28 14:04:46 +08:00
|
|
|
|
DomEventService.AddEventListener(Ref, "compositionstart", OnCompositionStart);
|
|
|
|
|
DomEventService.AddEventListener(Ref, "compositionend", OnCompositionEnd);
|
|
|
|
|
|
|
|
|
|
if (this.AutoFocus)
|
|
|
|
|
{
|
|
|
|
|
await this.Focus();
|
|
|
|
|
}
|
2020-06-02 13:26:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-28 14:04:46 +08:00
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
DomEventService.RemoveEventListerner<JsonElement>(Ref, "compositionstart", OnCompositionStart);
|
|
|
|
|
DomEventService.RemoveEventListerner<JsonElement>(Ref, "compositionend", OnCompositionEnd);
|
|
|
|
|
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-07 12:44:10 +08:00
|
|
|
|
protected virtual string GetClearIconCls()
|
|
|
|
|
{
|
|
|
|
|
return $"{PrefixCls}-clear-icon";
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 09:06:56 +08:00
|
|
|
|
protected override void OnValueChange(TValue value)
|
|
|
|
|
{
|
|
|
|
|
base.OnValueChange(value);
|
|
|
|
|
_inputValue = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-23 09:31:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Invoked when user add/remove content
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="args"></param>
|
|
|
|
|
/// <returns></returns>
|
2020-04-24 18:32:50 +08:00
|
|
|
|
protected virtual async void OnInputAsync(ChangeEventArgs args)
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
2020-06-27 01:20:52 +08:00
|
|
|
|
bool flag = !(!string.IsNullOrEmpty(Value?.ToString()) && args != null && !string.IsNullOrEmpty(args.Value.ToString()));
|
2020-04-24 18:32:50 +08:00
|
|
|
|
|
2020-07-30 09:06:56 +08:00
|
|
|
|
if (TryParseValueFromString(args?.Value.ToString(), out TValue value, out var error))
|
|
|
|
|
{
|
|
|
|
|
_inputValue = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-12 00:28:10 +08:00
|
|
|
|
if (_allowClear && flag)
|
2020-03-23 09:31:08 +08:00
|
|
|
|
{
|
2020-07-12 00:28:10 +08:00
|
|
|
|
ToggleClearBtn();
|
2020-03-23 09:31:08 +08:00
|
|
|
|
}
|
2020-07-07 12:44:10 +08:00
|
|
|
|
|
2020-07-12 00:28:10 +08:00
|
|
|
|
if (OnInput.HasDelegate)
|
2020-03-26 10:45:35 +08:00
|
|
|
|
{
|
2020-07-12 00:28:10 +08:00
|
|
|
|
await OnInput.InvokeAsync(args);
|
2020-03-26 10:45:35 +08:00
|
|
|
|
}
|
2020-03-23 09:31:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void BuildRenderTree(RenderTreeBuilder builder)
|
|
|
|
|
{
|
2020-04-24 18:32:50 +08:00
|
|
|
|
if (builder != null)
|
|
|
|
|
{
|
|
|
|
|
base.BuildRenderTree(builder);
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
string container = "input";
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
if (AddOnBefore != null || AddOnAfter != null)
|
|
|
|
|
{
|
|
|
|
|
container = "groupWrapper";
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.OpenElement(1, "span");
|
|
|
|
|
builder.AddAttribute(2, "class", GroupWrapperClass);
|
|
|
|
|
builder.AddAttribute(3, "style", Style);
|
|
|
|
|
builder.OpenElement(4, "span");
|
|
|
|
|
builder.AddAttribute(5, "class", $"{PrefixCls}-wrapper {PrefixCls}-group");
|
2020-04-24 18:32:50 +08:00
|
|
|
|
}
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
if (AddOnBefore != null)
|
|
|
|
|
{
|
|
|
|
|
// addOnBefore
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.OpenElement(11, "span");
|
|
|
|
|
builder.AddAttribute(12, "class", $"{PrefixCls}-group-addon");
|
|
|
|
|
builder.AddContent(13, AddOnBefore);
|
2020-04-24 18:32:50 +08:00
|
|
|
|
builder.CloseElement();
|
|
|
|
|
}
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
if (Prefix != null || Suffix != null)
|
|
|
|
|
{
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.OpenElement(21, "span");
|
|
|
|
|
builder.AddAttribute(22, "class", AffixWrapperClass);
|
2020-04-24 18:32:50 +08:00
|
|
|
|
if (container == "input")
|
|
|
|
|
{
|
|
|
|
|
container = "affixWrapper";
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.AddAttribute(23, "style", Style);
|
2020-04-24 18:32:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Prefix != null)
|
|
|
|
|
{
|
|
|
|
|
// prefix
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.OpenElement(31, "span");
|
|
|
|
|
builder.AddAttribute(32, "class", $"{PrefixCls}-prefix");
|
|
|
|
|
builder.AddContent(33, Prefix);
|
2020-04-24 18:32:50 +08:00
|
|
|
|
builder.CloseElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// input
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.OpenElement(41, "input");
|
|
|
|
|
builder.AddAttribute(42, "class", ClassMapper.Class);
|
2020-03-23 09:31:08 +08:00
|
|
|
|
if (container == "input")
|
|
|
|
|
{
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.AddAttribute(43, "style", Style);
|
2020-03-23 09:31:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
if (Attributes != null)
|
|
|
|
|
{
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.AddMultipleAttributes(44, Attributes);
|
2020-06-27 01:20:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (AdditionalAttributes != null)
|
|
|
|
|
{
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.AddMultipleAttributes(45, AdditionalAttributes);
|
2020-04-24 18:32:50 +08:00
|
|
|
|
}
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.AddAttribute(50, "Id", Id);
|
2020-10-12 00:20:33 +08:00
|
|
|
|
builder.AddAttribute(51, "type", Type);
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.AddAttribute(60, "placeholder", Placeholder);
|
|
|
|
|
builder.AddAttribute(61, "value", CurrentValue);
|
2020-07-30 09:06:56 +08:00
|
|
|
|
|
|
|
|
|
// onchange 和 onblur 事件会导致点击 OnSearch 按钮时不触发 Click 事件,暂时取消这两个事件
|
|
|
|
|
if (!IgnoreOnChangeAndBlur)
|
|
|
|
|
{
|
|
|
|
|
builder.AddAttribute(62, "onchange", CallbackFactory.Create(this, OnChangeAsync));
|
|
|
|
|
builder.AddAttribute(65, "onblur", CallbackFactory.Create(this, OnBlurAsync));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder.AddAttribute(63, "onkeypress", CallbackFactory.Create(this, OnKeyPressAsync));
|
2020-08-26 22:37:08 +08:00
|
|
|
|
builder.AddAttribute(63, "onkeydown", CallbackFactory.Create(this, OnkeyDownAsync));
|
2020-07-30 09:06:56 +08:00
|
|
|
|
builder.AddAttribute(63, "onkeyup", CallbackFactory.Create(this, OnKeyUpAsync));
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.AddAttribute(64, "oninput", CallbackFactory.Create(this, OnInputAsync));
|
2020-08-26 22:37:08 +08:00
|
|
|
|
builder.AddAttribute(66, "onfocus", CallbackFactory.Create(this, OnFocusAsync));
|
2020-10-12 00:20:33 +08:00
|
|
|
|
builder.AddAttribute(67, "onmouseup", CallbackFactory.Create(this, OnMouseUpAsync));
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.AddElementReferenceCapture(68, r => Ref = r);
|
2020-03-23 09:31:08 +08:00
|
|
|
|
builder.CloseElement();
|
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
if (Suffix != null)
|
|
|
|
|
{
|
|
|
|
|
// suffix
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.OpenElement(71, "span");
|
|
|
|
|
builder.AddAttribute(72, "class", $"{PrefixCls}-suffix");
|
|
|
|
|
builder.AddContent(73, Suffix);
|
2020-04-24 18:32:50 +08:00
|
|
|
|
builder.CloseElement();
|
|
|
|
|
}
|
2020-03-23 09:31:08 +08:00
|
|
|
|
|
2020-04-24 18:32:50 +08:00
|
|
|
|
if (Prefix != null || Suffix != null)
|
|
|
|
|
{
|
|
|
|
|
builder.CloseElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (AddOnAfter != null)
|
|
|
|
|
{
|
|
|
|
|
// addOnAfter
|
2020-07-07 12:44:10 +08:00
|
|
|
|
builder.OpenElement(81, "span");
|
|
|
|
|
builder.AddAttribute(82, "class", $"{PrefixCls}-group-addon");
|
|
|
|
|
builder.AddContent(83, AddOnAfter);
|
2020-04-24 18:32:50 +08:00
|
|
|
|
builder.CloseElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (AddOnBefore != null || AddOnAfter != null)
|
|
|
|
|
{
|
|
|
|
|
builder.CloseElement();
|
|
|
|
|
builder.CloseElement();
|
|
|
|
|
}
|
2020-03-23 09:31:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-23 17:13:56 +08:00
|
|
|
|
}
|