[Slider] Make label respond to `Disabled` state (#2796)

* Fix #2794 by adding an owning slider cascading parameter and set label's disabled state to owner value

* Undo refactor. not needed anymore

* Fix test
This commit is contained in:
Vincent Baaij 2024-10-12 13:04:03 +02:00 коммит произвёл GitHub
Родитель 2d81f01e4e
Коммит 0b10a93af5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
7 изменённых файлов: 45 добавлений и 28 удалений

Просмотреть файл

@ -8427,7 +8427,7 @@
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentSliderLabel`1.Disabled">
<summary>
Gets or sets disabled state of the label. This is generally controlled by the parent.
Gets the disabled state of the label. This is controlled by the owning <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentSlider`1"/>.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentSliderLabel`1.ChildContent">
@ -8833,16 +8833,19 @@
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.HorizontalAlignment">
<summary>
Gets or sets the horizontal alignment of the components in the stack.
Default is <see cref="F:Microsoft.FluentUI.AspNetCore.Components.HorizontalAlignment.Left"/>
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.VerticalAlignment">
<summary>
Gets or sets the vertical alignment of the components in the stack.
Default is <see cref="F:Microsoft.FluentUI.AspNetCore.Components.VerticalAlignment.Top"/>
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.Orientation">
<summary>
Gets or sets the orientation of the stacked components.
Default is <see cref="F:Microsoft.FluentUI.AspNetCore.Components.Orientation.Horizontal"/>.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.Width">

Просмотреть файл

@ -2,21 +2,23 @@
@inherits FluentInputBase<TValue>
@typeparam TValue
@attribute [CascadingTypeParameter(nameof(TValue))]
<FluentInputLabel ForId="@Id" Label="@Label" AriaLabel="@AriaLabel" ChildContent="@LabelTemplate" Required="@Required" style="margin-bottom: calc(var(--design-unit) * 3px);" />
<fluent-slider @ref=Element
class="@ClassValue"
style="@StyleValue"
readonly="@ReadOnly"
min="@FormatValueAsString(Min)"
max="@FormatValueAsString(Max)"
step="@FormatValueAsString(Step)"
orientation="@Orientation.ToAttributeValue()"
mode="@Mode.ToAttributeValue()"
id="@Id"
value="@FormatValueAsString(Value)"
disabled="@Disabled"
name=@Name
required=@Required
@onsliderchange="@ChangeHandlerAsync">
@ChildContent
</fluent-slider>
<CascadingValue Value="this" IsFixed="true">
<FluentInputLabel ForId="@Id" Label="@Label" AriaLabel="@AriaLabel" ChildContent="@LabelTemplate" Required="@Required" style="margin-bottom: calc(var(--design-unit) * 3px);" />
<fluent-slider @ref=Element
class="@ClassValue"
style="@StyleValue"
readonly="@ReadOnly"
min="@FormatValueAsString(Min)"
max="@FormatValueAsString(Max)"
step="@FormatValueAsString(Step)"
orientation="@Orientation.ToAttributeValue()"
mode="@Mode.ToAttributeValue()"
id="@Id"
value="@FormatValueAsString(Value)"
disabled="@Disabled"
name=@Name
required=@Required
@onsliderchange="@ChangeHandlerAsync">
@ChildContent
</fluent-slider>
</CascadingValue>

Просмотреть файл

@ -1,6 +1,6 @@
@namespace Microsoft.FluentUI.AspNetCore.Components
@namespace Microsoft.FluentUI.AspNetCore.Components
@inherits FluentComponentBase
@typeparam TValue
@typeparam TValue where TValue : System.Numerics.INumber<TValue>
<fluent-slider-label @ref=Element
id="@Id"
class="@Class"

Просмотреть файл

@ -8,6 +8,7 @@ namespace Microsoft.FluentUI.AspNetCore.Components;
public partial class FluentSliderLabel<TValue> : FluentComponentBase, IAsyncDisposable
{
private const string JAVASCRIPT_FILE = "./_content/Microsoft.FluentUI.AspNetCore.Components/Components/Slider/FluentSliderLabel.razor.js";
private bool? _disabled;
public FluentSliderLabel()
{
@ -38,10 +39,17 @@ public partial class FluentSliderLabel<TValue> : FluentComponentBase, IAsyncDisp
public bool? HideMark { get; set; }
/// <summary>
/// Gets or sets disabled state of the label. This is generally controlled by the parent.
/// Gets the disabled state of the label. This is controlled by the owning <see cref="FluentSlider{TValue}"/>.
/// </summary>
[Parameter]
public bool? Disabled { get; set; }
public bool? Disabled
{
get => Owner is null ? _disabled : Owner.Disabled;
set => _disabled = Owner is null ? value : Owner.Disabled;
}
[CascadingParameter]
internal FluentSlider<TValue> Owner { get; set; } = default!;
/// <summary>
/// Gets or sets the content to be rendered inside the component.

Просмотреть файл

@ -0,0 +1,4 @@
<fluent-slider-label id="xxx" position="0" blazor:elementreference="xxx">
<b>render me</b>
</fluent-slider-label>

Просмотреть файл

@ -13,17 +13,21 @@ public class FluentSliderLabelTests : TestBase
}
[Fact]
public void FluentSliderLaber_Default()
public void FluentSliderLabel_Default()
{
//Arrange
FluentSlider<int> slider = new();
var childContent = "<b>render me</b>";
int position = default!;
bool? hideMark = default!;
bool? disabled = default!;
var cut = TestContext.RenderComponent<FluentSliderLabel<int>>(parameters => parameters
.Add(p => p.Position, position)
.Add(p => p.HideMark, hideMark)
.Add(p => p.Disabled, disabled)
.AddCascadingValue(slider)
.AddChildContent(childContent)
);
//Act

Просмотреть файл

@ -1,4 +0,0 @@
<fluent-slider-label position="0" blazor:elementreference="xxx">
<b>render me</b>
</fluent-slider-label>