Skip to content

Commit

Permalink
Update CheckboxThreeStates and FluentCheckbox components
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AClerbois committed Jan 26, 2025
1 parent 7ffc94d commit 99c37b7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
<div>
<FluentCheckbox @bind-CheckState="checkState"
<FluentCheckbox @bind-CheckState="checkState1"
@bind-Value="value1"
ThreeState="true"
Label="Three state" />
- CheckState is @(checkState is null ? "(null indeterminate)" : checkState.Value ? "checked" : "unchecked")
Label="Three state = true" />
<span style="width: 50px; display: inline-block" />
Value = @value1- CheckState is @(checkState1 is null ? "(null indeterminate)" : checkState1.Value.ToString())
<br />

<FluentCheckbox @bind-Value="value2"
ThreeState="false"
Label="Three state = false" />
<span style="width: 50px; display: inline-block" />
Value = @value2
<br />
<FluentCheckbox @bind-CheckState="checkStateThreeStateOrderUncheckToIntermediate"
@bind-Value="valueThreeStateOrderUncheckToIntermediate"
ThreeState="true"
ThreeStateOrderUncheckToIntermediate="true"
Label="Three state with order uncheck to intermediate" />
- CheckState is @(checkStateThreeStateOrderUncheckToIntermediate is null ? "(null indeterminate)" : checkStateThreeStateOrderUncheckToIntermediate.Value ? "checked" : "unchecked")
<span style="width: 50px; display: inline-block" />
Value: @valueThreeStateOrderUncheckToIntermediate - CheckState is
@(checkStateThreeStateOrderUncheckToIntermediate is null ? "(null indeterminate)" : checkStateThreeStateOrderUncheckToIntermediate.Value.ToString())

<br />
<FluentCheckbox @bind-CheckState="checkStateShowIntermediateWithThreeState"
@bind-Value="valueShowIntermediateWithThreeState"
ThreeState="true"
ThreeStateOrderUncheckToIntermediate="true"
Label="Three state with show intermediate" />
<span style="width: 50px; display: inline-block" />
Value: @valueShowIntermediateWithThreeState - CheckState is
@(checkStateShowIntermediateWithThreeState is null ? "(null indeterminate)" : checkStateShowIntermediateWithThreeState.Value.ToString())
</div>

@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;
}
11 changes: 10 additions & 1 deletion src/Core/Components/Checkbox/FluentCheckbox.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected override async Task OnInitializedAsync()

if (!ShowIndeterminate)
{
await SetValueChangedAsync(Checked);
await SetValueChangedAsync(true);
Indeterminate = true;
await SetCheckStateChangedAsync(null);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 99c37b7

Please sign in to comment.