Skip to content

Commit 3fc5668

Browse files
dvoituronvnbaaij
andauthored
[dev-v5] Fix Slider - add ImmediateDelay (#3986)
* Add ImmediateDelay * Fix Unit Test --------- Co-authored-by: Vincent Baaij <vnbaaij@outlook.com>
1 parent e0c4ccc commit 3fc5668

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Core/Components/Slider/FluentSlider.razor.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.AspNetCore.Components;
77
using Microsoft.AspNetCore.Components.Web;
88
using Microsoft.FluentUI.AspNetCore.Components.Extensions;
9+
using Microsoft.FluentUI.AspNetCore.Components.Utilities;
910

1011
namespace Microsoft.FluentUI.AspNetCore.Components;
1112

@@ -16,6 +17,8 @@ namespace Microsoft.FluentUI.AspNetCore.Components;
1617
public partial class FluentSlider<TValue> : FluentInputBase<TValue>, ITooltipComponent
1718
where TValue : struct, IComparable<TValue>
1819
{
20+
private readonly Debounce _debounce = new();
21+
1922
/// <summary>
2023
/// Initializes a new instance of the <see cref="FluentSlider{TValue}"/> class.
2124
/// </summary>
@@ -80,6 +83,12 @@ public FluentSlider(LibraryConfiguration configuration) : base(configuration)
8083
[Parameter]
8184
public string? Tooltip { get; set; }
8285

86+
/// <summary>
87+
/// Gets or sets the delay, in milliseconds, before to raise the change event.
88+
/// </summary>
89+
[Parameter]
90+
public ushort ImmediateDelay { get; set; } = 60;
91+
8392
/// <summary />
8493
protected override async Task OnInitializedAsync()
8594
{
@@ -107,6 +116,15 @@ protected virtual Task FocusOutHandlerAsync(FocusEventArgs e)
107116
return Task.CompletedTask;
108117
}
109118

119+
/// <summary />
120+
protected override Task ChangeHandlerAsync(ChangeEventArgs e)
121+
{
122+
return _debounce.RunAsync(ImmediateDelay, () =>
123+
{
124+
return base.ChangeHandlerAsync(e);
125+
});
126+
}
127+
110128
/// <summary>
111129
/// Parses a string to create the <see cref="Microsoft.AspNetCore.Components.Forms.InputBase{TValue}.Value"/>.
112130
/// </summary>

tests/Core/Components/Slider/FluentSliderTests.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
{
132132
// Arrange
133133
var step = (T)Convert.ChangeType(1, typeof(T));
134-
var cut = Render(@<FluentSlider TValue="T" @bind-Value="@value" Step="@step" />);
134+
var cut = Render(@<FluentSlider TValue="T" @bind-Value="@value" Step="@step" ImmediateDelay="0" />);
135135

136136
var slider = cut.Find("fluent-slider");
137137
var valueAttribute = slider.GetAttribute("value");

0 commit comments

Comments
 (0)