Skip to content

Commit cf47c43

Browse files
oneolddevvnbaaij
authored andcommitted
[Slider] Fix FluentSlider two-way binding issue [microsoft#2609} (microsoft#2665)
* Skip publish symbols step for now * fix problem where thumbnail is not being rendered when value is changed programmtically * limits calls to updateSlider * missed a file --------- Co-authored-by: Vincent Baaij <[email protected]>
1 parent eaaff76 commit cf47c43

File tree

3 files changed

+118
-9
lines changed

3 files changed

+118
-9
lines changed

eng/pipelines/build-all-lib.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ extends:
194194

195195
# Index sources and publish symbols
196196

197-
- task: PublishSymbols@2
198-
inputs:
199-
SearchPattern: '**/bin/**/*.pdb' # string. Required. Search pattern. Default: **/bin/**/*.pdb.
200-
SymbolServerType: 'TeamServices'
197+
#- task: PublishSymbols@2
198+
# inputs:
199+
# SearchPattern: '**/bin/**/*.pdb' # string. Required. Search pattern. Default: **/bin/**/*.pdb.
200+
# SymbolServerType: 'TeamServices'
201201

202202
# Since NuGet packages are generated during the build, we need to copy them to the artifacts folder.
203203
- task: CopyFiles@2

examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8230,6 +8230,12 @@
82308230
Gets or sets the content to be rendered inside the component.
82318231
</summary>
82328232
</member>
8233+
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentSlider`1.JSRuntime">
8234+
<summary />
8235+
</member>
8236+
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentSlider`1._jsModule">
8237+
<summary />
8238+
</member>
82338239
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentSlider`1.Min">
82348240
<summary>
82358241
Gets or sets the slider's minimal value.
@@ -8247,7 +8253,7 @@
82478253
</member>
82488254
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentSlider`1.Orientation">
82498255
<summary>
8250-
Gets or sets the orentation of the slider. See <see cref="T:Microsoft.FluentUI.AspNetCore.Components.Orientation"/>
8256+
Gets or sets the orientation of the slider. See <see cref="T:Microsoft.FluentUI.AspNetCore.Components.Orientation"/>
82518257
</summary>
82528258
</member>
82538259
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentSlider`1.Mode">

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

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,87 @@
1+
// ------------------------------------------------------------------------
2+
// MIT License - Copyright (c) Microsoft Corporation. All rights reserved.
3+
// ------------------------------------------------------------------------
4+
15
using System.Diagnostics.CodeAnalysis;
26
using System.Globalization;
37

48
using Microsoft.AspNetCore.Components;
59
using Microsoft.FluentUI.AspNetCore.Components.Extensions;
610
using Microsoft.FluentUI.AspNetCore.Components.Utilities;
11+
using Microsoft.JSInterop;
712

813
namespace Microsoft.FluentUI.AspNetCore.Components;
914

10-
public partial class FluentSlider<TValue> : FluentInputBase<TValue>
15+
public partial class FluentSlider<TValue> : FluentInputBase<TValue>, IAsyncDisposable
1116
where TValue : System.Numerics.INumber<TValue>
1217
{
18+
private const string JAVASCRIPT_FILE = "./_content/Microsoft.FluentUI.AspNetCore.Components/Components/Slider/FluentSlider.razor.js";
19+
20+
/// <summary />
21+
[Inject]
22+
private IJSRuntime JSRuntime { get; set; } = default!;
23+
24+
/// <summary />
25+
private IJSObjectReference? _jsModule { get; set; }
26+
27+
private TValue? max;
28+
private TValue? min;
29+
private bool updateSliderThumb = false;
30+
private bool userChangedValue = false;
31+
1332
/// <summary>
1433
/// Gets or sets the slider's minimal value.
1534
/// </summary>
1635
[Parameter, EditorRequired]
17-
public TValue? Min { get; set; }
36+
public TValue? Min
37+
{
38+
get => min;
39+
set
40+
{
41+
if (min != value)
42+
{
43+
min = value;
44+
updateSliderThumb = true;
45+
}
46+
}
47+
}
1848

1949
/// <summary>
2050
/// Gets or sets the slider's maximum value.
2151
/// </summary>
2252
[Parameter, EditorRequired]
23-
public TValue? Max { get; set; }
53+
public TValue? Max
54+
{
55+
get => max;
56+
set
57+
{
58+
if (max != value)
59+
{
60+
max = value;
61+
updateSliderThumb = true;
62+
}
63+
}
64+
}
65+
66+
public override TValue? Value
67+
{
68+
get => base.Value;
69+
set
70+
{
71+
if (base.Value != value)
72+
{
73+
base.Value = value;
74+
if (userChangedValue)
75+
{
76+
userChangedValue = false;
77+
}
78+
else
79+
{
80+
updateSliderThumb = true;
81+
}
82+
}
83+
}
84+
}
2485

2586
/// <summary>
2687
/// Gets or sets the slider's step value.
@@ -29,7 +90,7 @@ public partial class FluentSlider<TValue> : FluentInputBase<TValue>
2990
public TValue? Step { get; set; }
3091

3192
/// <summary>
32-
/// Gets or sets the orentation of the slider. See <see cref="AspNetCore.Components.Orientation"/>
93+
/// Gets or sets the orientation of the slider. See <see cref="AspNetCore.Components.Orientation"/>
3394
/// </summary>
3495
[Parameter]
3596
public Orientation? Orientation { get; set; }
@@ -46,6 +107,31 @@ public partial class FluentSlider<TValue> : FluentInputBase<TValue>
46107
[Parameter]
47108
public RenderFragment? ChildContent { get; set; }
48109

110+
protected override async Task OnAfterRenderAsync(bool firstRender)
111+
{
112+
if (firstRender)
113+
{
114+
_jsModule ??= await JSRuntime.InvokeAsync<IJSObjectReference>("import", JAVASCRIPT_FILE);
115+
}
116+
else
117+
{
118+
if (updateSliderThumb)
119+
{
120+
updateSliderThumb = false;
121+
if (_jsModule is not null)
122+
{
123+
await _jsModule!.InvokeVoidAsync("updateSlider", Element);
124+
}
125+
}
126+
}
127+
}
128+
129+
protected override Task ChangeHandlerAsync(ChangeEventArgs e)
130+
{
131+
userChangedValue = true;
132+
return base.ChangeHandlerAsync(e);
133+
}
134+
49135
protected override string? ClassValue
50136
{
51137
get
@@ -120,4 +206,21 @@ private static string GetStepAttributeValue()
120206
throw new InvalidOperationException($"The type '{targetType}' is not a supported numeric type.");
121207
}
122208
}
209+
210+
public async ValueTask DisposeAsync()
211+
{
212+
try
213+
{
214+
if (_jsModule is not null)
215+
{
216+
await _jsModule.DisposeAsync();
217+
}
218+
}
219+
catch (Exception ex) when (ex is JSDisconnectedException ||
220+
ex is OperationCanceledException)
221+
{
222+
// The JSRuntime side may routinely be gone already if the reason we're disposing is that
223+
// the client disconnected. This is not an error.
224+
}
225+
}
123226
}

0 commit comments

Comments
 (0)