diff --git a/eng/pipelines/build-all-lib.yml b/eng/pipelines/build-all-lib.yml index 2bbada0c31..3c6d1a9fd1 100644 --- a/eng/pipelines/build-all-lib.yml +++ b/eng/pipelines/build-all-lib.yml @@ -194,10 +194,10 @@ extends: # Index sources and publish symbols - - task: PublishSymbols@2 - inputs: - SearchPattern: '**/bin/**/*.pdb' # string. Required. Search pattern. Default: **/bin/**/*.pdb. - SymbolServerType: 'TeamServices' + #- task: PublishSymbols@2 + # inputs: + # SearchPattern: '**/bin/**/*.pdb' # string. Required. Search pattern. Default: **/bin/**/*.pdb. + # SymbolServerType: 'TeamServices' # Since NuGet packages are generated during the build, we need to copy them to the artifacts folder. - task: CopyFiles@2 diff --git a/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml b/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml index 186db9c0a0..bc9645e5e0 100644 --- a/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml +++ b/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml @@ -8230,6 +8230,12 @@ Gets or sets the content to be rendered inside the component. + + + + + + Gets or sets the slider's minimal value. @@ -8247,7 +8253,7 @@ - Gets or sets the orentation of the slider. See + Gets or sets the orientation of the slider. See diff --git a/src/Core/Components/Slider/FluentSlider.razor.cs b/src/Core/Components/Slider/FluentSlider.razor.cs index 669d320a13..fa8fa2347d 100644 --- a/src/Core/Components/Slider/FluentSlider.razor.cs +++ b/src/Core/Components/Slider/FluentSlider.razor.cs @@ -1,26 +1,87 @@ +// ------------------------------------------------------------------------ +// MIT License - Copyright (c) Microsoft Corporation. All rights reserved. +// ------------------------------------------------------------------------ + using System.Diagnostics.CodeAnalysis; using System.Globalization; using Microsoft.AspNetCore.Components; using Microsoft.FluentUI.AspNetCore.Components.Extensions; using Microsoft.FluentUI.AspNetCore.Components.Utilities; +using Microsoft.JSInterop; namespace Microsoft.FluentUI.AspNetCore.Components; -public partial class FluentSlider : FluentInputBase +public partial class FluentSlider : FluentInputBase, IAsyncDisposable where TValue : System.Numerics.INumber { + private const string JAVASCRIPT_FILE = "./_content/Microsoft.FluentUI.AspNetCore.Components/Components/Slider/FluentSlider.razor.js"; + + /// + [Inject] + private IJSRuntime JSRuntime { get; set; } = default!; + + /// + private IJSObjectReference? _jsModule { get; set; } + + private TValue? max; + private TValue? min; + private bool updateSliderThumb = false; + private bool userChangedValue = false; + /// /// Gets or sets the slider's minimal value. /// [Parameter, EditorRequired] - public TValue? Min { get; set; } + public TValue? Min + { + get => min; + set + { + if (min != value) + { + min = value; + updateSliderThumb = true; + } + } + } /// /// Gets or sets the slider's maximum value. /// [Parameter, EditorRequired] - public TValue? Max { get; set; } + public TValue? Max + { + get => max; + set + { + if (max != value) + { + max = value; + updateSliderThumb = true; + } + } + } + + public override TValue? Value + { + get => base.Value; + set + { + if (base.Value != value) + { + base.Value = value; + if (userChangedValue) + { + userChangedValue = false; + } + else + { + updateSliderThumb = true; + } + } + } + } /// /// Gets or sets the slider's step value. @@ -29,7 +90,7 @@ public partial class FluentSlider : FluentInputBase public TValue? Step { get; set; } /// - /// Gets or sets the orentation of the slider. See + /// Gets or sets the orientation of the slider. See /// [Parameter] public Orientation? Orientation { get; set; } @@ -46,6 +107,31 @@ public partial class FluentSlider : FluentInputBase [Parameter] public RenderFragment? ChildContent { get; set; } + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + _jsModule ??= await JSRuntime.InvokeAsync("import", JAVASCRIPT_FILE); + } + else + { + if (updateSliderThumb) + { + updateSliderThumb = false; + if (_jsModule is not null) + { + await _jsModule!.InvokeVoidAsync("updateSlider", Element); + } + } + } + } + + protected override Task ChangeHandlerAsync(ChangeEventArgs e) + { + userChangedValue = true; + return base.ChangeHandlerAsync(e); + } + protected override string? ClassValue { get @@ -120,4 +206,21 @@ private static string GetStepAttributeValue() throw new InvalidOperationException($"The type '{targetType}' is not a supported numeric type."); } } + + public async ValueTask DisposeAsync() + { + try + { + if (_jsModule is not null) + { + await _jsModule.DisposeAsync(); + } + } + catch (Exception ex) when (ex is JSDisconnectedException || + ex is OperationCanceledException) + { + // The JSRuntime side may routinely be gone already if the reason we're disposing is that + // the client disconnected. This is not an error. + } + } }