Skip to content

Commit

Permalink
Fix Splitter Infinite Loop (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
mckaragoz authored Apr 13, 2024
1 parent 69cd70b commit 2ae84bc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public void SpeedDialPageRenderTest()
comp.Markup.Should().NotBeNullOrEmpty();
}

[Test]
public void SplitterPageRenderTest()
{
var comp = Context.RenderComponent<SplitterPage>();
comp.Markup.Should().NotBeNullOrEmpty();
}

[Test]
public void StepperPageRenderTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
@inherits MudComponentBase

<div class="@Classname" style="@Style">
<MudSlider @ref="_slider" Value="@Dimension" ValueChanged="@UpdateDimension" ondblclick="@OnDoubleClick()"
@* Don't make OnDoubleClick to method, causes infinite loop *@
<MudSlider @ref="_slider" @bind-Value="@Dimension" @bind-Value:after="@(() => UpdateDimension(_slider.Value))" ondblclick="@OnDoubleClick"
T="double" Min="0" Max="100" Step="@Sensitivity" Disabled="@(!EnableSlide)"
Class="@SliderClassname" Style="overflow: hidden; z-index: 6" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public partial class MudSplitter : MudComponentBase
public EventCallback<double> DimensionChanged { get; set; }

/// <summary>
///
/// Fires when double click.
/// </summary>
[Parameter]
public EventCallback OnDoubleClicked { get; set; }
Expand All @@ -159,7 +159,7 @@ public partial class MudSplitter : MudComponentBase
/// </summary>
/// <param name="percentage"></param>
/// <returns></returns>
protected Task UpdateDimension(double percentage)
protected async Task UpdateDimension(double percentage)
{
Dimension = percentage;

Expand All @@ -169,17 +169,19 @@ protected Task UpdateDimension(double percentage)
Dimension = 100;

if (DimensionChanged.HasDelegate)
_ = DimensionChanged.InvokeAsync(percentage);
{
await DimensionChanged.InvokeAsync(percentage);
}

return Task.CompletedTask;
//return Task.CompletedTask;
}

Task OnDoubleClick()
private async Task OnDoubleClick()
{
if (OnDoubleClicked.HasDelegate)
_ = OnDoubleClicked.InvokeAsync();
await OnDoubleClicked.InvokeAsync();

return Task.CompletedTask;
//return Task.CompletedTask;
}
}
}
30 changes: 17 additions & 13 deletions ComponentViewer.Docs/Pages/Examples/SplitterExample1.razor
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,23 @@
</MudGrid>

@code {
MudSplitter? _splitter;
Color _color;
string _height = "400px";
double _sensitivity = 0.1d;
double _percentage = 50;
bool _sliderEnabled = true;
bool _marginEnabled = true;
bool _borderedEnabled = true;
bool _doubleClickEnabled = true;
MudSplitter? _splitter;
Color _color;
string _height = "400px";
double _sensitivity = 0.1d;
double _percentage = 50;
bool _sliderEnabled = true;
bool _marginEnabled = true;
bool _borderedEnabled = true;
bool _doubleClickEnabled = true;

void OnDoubleClicked()
{
if (_doubleClickEnabled)
_percentage = 50;
private Task OnDoubleClicked()
{
if (_doubleClickEnabled)
{
_percentage = 50;
}

return Task.CompletedTask;
}
}

0 comments on commit 2ae84bc

Please sign in to comment.