From 99c37b748d0c308c256a51ff89e9eed69293ea0c Mon Sep 17 00:00:00 2001 From: Adrien Clerbois Date: Sun, 26 Jan 2025 19:05:36 +0100 Subject: [PATCH] Update CheckboxThreeStates and FluentCheckbox components Updated CheckboxThreeStates.razor to include additional FluentCheckbox components and modify existing ones. Renamed variables and added new ones in the @code section. Modified OnInitializedAsync and SetCheckStateChangedAsync methods in FluentCheckbox.razor.cs to handle value changes more effectively. --- .../Examples/CheckboxThreeStates.razor | 37 ++++++++++++++++--- .../Checkbox/FluentCheckbox.razor.cs | 11 +++++- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/examples/Demo/FluentUI.Demo.Client/Documentation/Components/Checkbox/Examples/CheckboxThreeStates.razor b/examples/Demo/FluentUI.Demo.Client/Documentation/Components/Checkbox/Examples/CheckboxThreeStates.razor index 64eb6caa9..fe2c4a814 100644 --- a/examples/Demo/FluentUI.Demo.Client/Documentation/Components/Checkbox/Examples/CheckboxThreeStates.razor +++ b/examples/Demo/FluentUI.Demo.Client/Documentation/Components/Checkbox/Examples/CheckboxThreeStates.razor @@ -1,17 +1,44 @@ 
- - - CheckState is @(checkState is null ? "(null indeterminate)" : checkState.Value ? "checked" : "unchecked") + Label="Three state = true" /> + + Value = @value1- CheckState is @(checkState1 is null ? "(null indeterminate)" : checkState1.Value.ToString()) +
+ + + + Value = @value2
- - CheckState is @(checkStateThreeStateOrderUncheckToIntermediate is null ? "(null indeterminate)" : checkStateThreeStateOrderUncheckToIntermediate.Value ? "checked" : "unchecked") + + Value: @valueThreeStateOrderUncheckToIntermediate - CheckState is + @(checkStateThreeStateOrderUncheckToIntermediate is null ? "(null indeterminate)" : checkStateThreeStateOrderUncheckToIntermediate.Value.ToString()) + +
+ + + Value: @valueShowIntermediateWithThreeState - CheckState is + @(checkStateShowIntermediateWithThreeState is null ? "(null indeterminate)" : checkStateShowIntermediateWithThreeState.Value.ToString())
@code { - private bool? checkState = true; + private bool? checkState1 = true; + private bool value1 = false; + private bool value2 = false; private bool? checkStateThreeStateOrderUncheckToIntermediate = false; + private bool valueThreeStateOrderUncheckToIntermediate = false; + private bool valueShowIntermediateWithThreeState = false; + private bool? checkStateShowIntermediateWithThreeState = false; } diff --git a/src/Core/Components/Checkbox/FluentCheckbox.razor.cs b/src/Core/Components/Checkbox/FluentCheckbox.razor.cs index dc74d6e1e..7e0c6ffea 100644 --- a/src/Core/Components/Checkbox/FluentCheckbox.razor.cs +++ b/src/Core/Components/Checkbox/FluentCheckbox.razor.cs @@ -113,7 +113,7 @@ protected override async Task OnInitializedAsync() if (!ShowIndeterminate) { - await SetValueChangedAsync(Checked); + await SetValueChangedAsync(true); Indeterminate = true; await SetCheckStateChangedAsync(null); } @@ -185,6 +185,15 @@ private async Task SetCheckStateChangedAsync(bool? newValue) } CheckState = newValue; + if(newValue is null) + { + await SetValueChangedAsync(false); + } + else + { + await SetValueChangedAsync(newValue.Value); + } + if (CheckStateChanged.HasDelegate) { await CheckStateChanged.InvokeAsync(newValue);