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(Select): add OnInputChangedCallback parameter #3003

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>8.2.5</Version>
<Version>8.2.6-beta01</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
14 changes: 13 additions & 1 deletion src/BootstrapBlazor/Components/Select/Select.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ public partial class Select<TValue> : ISelect
[Parameter]
public bool IsEditable { get; set; }

/// <summary>
/// 获得/设置 选项输入更新后回调方法 默认 null
/// </summary>
/// <remarks>设置 <see cref="IsEditable"/> 后生效</remarks>
[Parameter]
public Func<string, Task>? OnInputChangedCallback { get; set; }

/// <summary>
/// 获得/设置 无搜索结果时显示文字
/// </summary>
Expand Down Expand Up @@ -436,7 +443,7 @@ private void OnClearValue()
CurrentValue = default;
}

private void OnChange(ChangeEventArgs args)
private async Task OnChange(ChangeEventArgs args)
{
if (args.Value is string v)
{
Expand All @@ -451,6 +458,11 @@ private void OnChange(ChangeEventArgs args)
Items = items;
}
CurrentValueAsString = v;

if (OnInputChangedCallback != null)
{
await OnInputChangedCallback(v);
}
}
}
}
7 changes: 7 additions & 0 deletions test/UnitTest/Components/SelectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -817,9 +817,15 @@ public async Task IsEditable_Ok()
var input = cut.Find(".form-select");
Assert.True(input.IsReadOnly());

var updated = false;
cut.SetParametersAndRender(pb =>
{
pb.Add(a => a.IsEditable, true);
pb.Add(a => a.OnInputChangedCallback, v =>
{
updated = true;
return Task.CompletedTask;
});
});
Assert.False(input.IsReadOnly());

Expand All @@ -828,5 +834,6 @@ await cut.InvokeAsync(() =>
input.Change("Test3");
});
Assert.Equal("Test3", cut.Instance.Value);
Assert.True(updated);
}
}