fix(module: checkbox): value binding for checkbox group (#2173)

* fix(module: checkbox): value binding for checkbox group
This commit is contained in:
James Yeung 2021-12-16 18:59:30 +08:00 committed by GitHub
parent f45e8f7b56
commit 6fcdbb9ad5
3 changed files with 37 additions and 14 deletions

View File

@ -17,7 +17,7 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.300
- name: Setup .NET 5
uses: actions/setup-dotnet@v1
with:
@ -26,7 +26,7 @@ jobs:
- name: Setup .NET 6.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.100
dotnet-version: 6.0.101
- uses: actions/setup-node@v1
with:
@ -46,8 +46,8 @@ jobs:
npm --prefix ./tests/AntDesign.Tests.Js run test-cov
find ./coverage ./tests -name "*coverage*.xml" -type f -exec cp {} ./ \;
- name: Upload coverage to Codecov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
files: ./coverage.cobertura.xml,./cobertura-coverage.xml
fail_ci_if_error: false
fail_ci_if_error: false

View File

@ -147,6 +147,26 @@ namespace AntDesign
}
});
}
else
{
var invokeChange = false;
_checkboxItems.ForEach(x =>
{
var checkBoxValue = x.Label.IsIn(value);
if (checkBoxValue != x.Value)
{
invokeChange = true;
x.SetValue(checkBoxValue);
OnCheckboxChange(x, false);
}
});
if (invokeChange)
{
InvokeValueChange();
}
}
}
protected override void OnAfterRender(bool firstRender)
@ -198,8 +218,9 @@ namespace AntDesign
/// Called when [checkbox change].
/// </summary>
/// <param name="checkbox">The checkbox.</param>
/// <param name="invokeOnChange">Flag for whether or not to depart for a change event.</param>
/// <returns></returns>
internal void OnCheckboxChange(Checkbox checkbox)
internal void OnCheckboxChange(Checkbox checkbox, bool invokeOnChange = true)
{
var index = _checkboxItems.IndexOf(checkbox);
int indexOffset;
@ -234,7 +255,16 @@ namespace AntDesign
}
});
CurrentValue = _currentValue();
if (invokeOnChange)
{
CurrentValue = _currentValue();
InvokeValueChange();
}
}
private void InvokeValueChange()
{
if (OnChange.HasDelegate)
{
OnChange.InvokeAsync(CurrentValue);

View File

@ -1,14 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup Condition="$(EnableAOT) == 'true'">
<TargetFrameworks>net5;net6</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="$(EnableAOT) != 'true'">
<TargetFramework>net5</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net5;net6</TargetFrameworks>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
</PropertyGroup>