Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FloatingLabel): add OnBlurAsync parameter #4523

Merged
merged 9 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions src/BootstrapBlazor/Components/Input/BootstrapInput.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ public partial class BootstrapInput<TValue>
[Parameter]
public bool AutoSetDefaultWhenNull { get; set; }

/// <summary>
/// 获得/设置 失去焦点回调方法 默认 null
/// </summary>
[Parameter]
public Func<TValue, Task>? OnBlurAsync { get; set; }

private string? ReadonlyString => Readonly ? "true" : null;

/// <summary>
Expand All @@ -53,15 +47,4 @@ protected override bool TryParseValueFromString(string value, [MaybeNullWhen(fal
}
return ret;
}

/// <summary>
/// OnBlur 方法
/// </summary>
protected virtual async Task OnBlur()
{
if (OnBlurAsync != null)
{
await OnBlurAsync(Value);
}
}
}
17 changes: 17 additions & 0 deletions src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ public abstract class BootstrapInputBase<TValue> : ValidateBase<TValue>
[Parameter]
public bool IsTrim { get; set; }

/// <summary>
/// 获得/设置 失去焦点回调方法 默认 null
/// </summary>
[Parameter]
public Func<TValue, Task>? OnBlurAsync { get; set; }

[CascadingParameter]
private Modal? Modal { get; set; }

Expand Down Expand Up @@ -191,6 +197,17 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
/// <returns></returns>
protected override bool TryParseValueFromString(string value, [MaybeNullWhen(false)] out TValue result, out string? validationErrorMessage) => base.TryParseValueFromString(IsTrim ? value.Trim() : value, out result, out validationErrorMessage);

/// <summary>
/// OnBlur 方法
/// </summary>
protected virtual async Task OnBlur()
{
if (OnBlurAsync != null)
{
await OnBlurAsync(Value);
}
}

/// <summary>
/// 客户端 EnterCallback 回调方法
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/Input/FloatingLabel.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
@inherits BootstrapInputBase<TValue>

<div class="@ClassString">
<input @attributes="@AdditionalAttributes" type="@Type" id="@Id" placeholder="@PlaceHolder" class="@ClassName" disabled="@Disabled" @bind-value="@CurrentValueAsString" @ref="FocusElement" />
<input @attributes="@AdditionalAttributes" type="@Type" id="@Id" placeholder="@PlaceHolder" class="@ClassName" disabled="@Disabled" @bind-value="@CurrentValueAsString" @onblur="@OnBlur" @ref="FocusElement" />
<label for="@Id">@DisplayText</label>
</div>
Loading