[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:
Родитель
2d81f01e4e
Коммит
0b10a93af5
|
@ -8427,7 +8427,7 @@
|
||||||
</member>
|
</member>
|
||||||
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentSliderLabel`1.Disabled">
|
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentSliderLabel`1.Disabled">
|
||||||
<summary>
|
<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>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentSliderLabel`1.ChildContent">
|
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentSliderLabel`1.ChildContent">
|
||||||
|
@ -8833,16 +8833,19 @@
|
||||||
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.HorizontalAlignment">
|
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.HorizontalAlignment">
|
||||||
<summary>
|
<summary>
|
||||||
Gets or sets the horizontal alignment of the components in the stack.
|
Gets or sets the horizontal alignment of the components in the stack.
|
||||||
|
Default is <see cref="F:Microsoft.FluentUI.AspNetCore.Components.HorizontalAlignment.Left"/>
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.VerticalAlignment">
|
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.VerticalAlignment">
|
||||||
<summary>
|
<summary>
|
||||||
Gets or sets the vertical alignment of the components in the stack.
|
Gets or sets the vertical alignment of the components in the stack.
|
||||||
|
Default is <see cref="F:Microsoft.FluentUI.AspNetCore.Components.VerticalAlignment.Top"/>
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.Orientation">
|
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.Orientation">
|
||||||
<summary>
|
<summary>
|
||||||
Gets or sets the orientation of the stacked components.
|
Gets or sets the orientation of the stacked components.
|
||||||
|
Default is <see cref="F:Microsoft.FluentUI.AspNetCore.Components.Orientation.Horizontal"/>.
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.Width">
|
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.Width">
|
||||||
|
|
|
@ -2,21 +2,23 @@
|
||||||
@inherits FluentInputBase<TValue>
|
@inherits FluentInputBase<TValue>
|
||||||
@typeparam TValue
|
@typeparam TValue
|
||||||
@attribute [CascadingTypeParameter(nameof(TValue))]
|
@attribute [CascadingTypeParameter(nameof(TValue))]
|
||||||
<FluentInputLabel ForId="@Id" Label="@Label" AriaLabel="@AriaLabel" ChildContent="@LabelTemplate" Required="@Required" style="margin-bottom: calc(var(--design-unit) * 3px);" />
|
<CascadingValue Value="this" IsFixed="true">
|
||||||
<fluent-slider @ref=Element
|
<FluentInputLabel ForId="@Id" Label="@Label" AriaLabel="@AriaLabel" ChildContent="@LabelTemplate" Required="@Required" style="margin-bottom: calc(var(--design-unit) * 3px);" />
|
||||||
class="@ClassValue"
|
<fluent-slider @ref=Element
|
||||||
style="@StyleValue"
|
class="@ClassValue"
|
||||||
readonly="@ReadOnly"
|
style="@StyleValue"
|
||||||
min="@FormatValueAsString(Min)"
|
readonly="@ReadOnly"
|
||||||
max="@FormatValueAsString(Max)"
|
min="@FormatValueAsString(Min)"
|
||||||
step="@FormatValueAsString(Step)"
|
max="@FormatValueAsString(Max)"
|
||||||
orientation="@Orientation.ToAttributeValue()"
|
step="@FormatValueAsString(Step)"
|
||||||
mode="@Mode.ToAttributeValue()"
|
orientation="@Orientation.ToAttributeValue()"
|
||||||
id="@Id"
|
mode="@Mode.ToAttributeValue()"
|
||||||
value="@FormatValueAsString(Value)"
|
id="@Id"
|
||||||
disabled="@Disabled"
|
value="@FormatValueAsString(Value)"
|
||||||
name=@Name
|
disabled="@Disabled"
|
||||||
required=@Required
|
name=@Name
|
||||||
@onsliderchange="@ChangeHandlerAsync">
|
required=@Required
|
||||||
@ChildContent
|
@onsliderchange="@ChangeHandlerAsync">
|
||||||
</fluent-slider>
|
@ChildContent
|
||||||
|
</fluent-slider>
|
||||||
|
</CascadingValue>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
@namespace Microsoft.FluentUI.AspNetCore.Components
|
@namespace Microsoft.FluentUI.AspNetCore.Components
|
||||||
@inherits FluentComponentBase
|
@inherits FluentComponentBase
|
||||||
@typeparam TValue
|
@typeparam TValue where TValue : System.Numerics.INumber<TValue>
|
||||||
<fluent-slider-label @ref=Element
|
<fluent-slider-label @ref=Element
|
||||||
id="@Id"
|
id="@Id"
|
||||||
class="@Class"
|
class="@Class"
|
||||||
|
|
|
@ -8,6 +8,7 @@ namespace Microsoft.FluentUI.AspNetCore.Components;
|
||||||
public partial class FluentSliderLabel<TValue> : FluentComponentBase, IAsyncDisposable
|
public partial class FluentSliderLabel<TValue> : FluentComponentBase, IAsyncDisposable
|
||||||
{
|
{
|
||||||
private const string JAVASCRIPT_FILE = "./_content/Microsoft.FluentUI.AspNetCore.Components/Components/Slider/FluentSliderLabel.razor.js";
|
private const string JAVASCRIPT_FILE = "./_content/Microsoft.FluentUI.AspNetCore.Components/Components/Slider/FluentSliderLabel.razor.js";
|
||||||
|
private bool? _disabled;
|
||||||
|
|
||||||
public FluentSliderLabel()
|
public FluentSliderLabel()
|
||||||
{
|
{
|
||||||
|
@ -38,10 +39,17 @@ public partial class FluentSliderLabel<TValue> : FluentComponentBase, IAsyncDisp
|
||||||
public bool? HideMark { get; set; }
|
public bool? HideMark { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
[Parameter]
|
[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>
|
/// <summary>
|
||||||
/// Gets or sets the content to be rendered inside the component.
|
/// 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]
|
[Fact]
|
||||||
public void FluentSliderLaber_Default()
|
public void FluentSliderLabel_Default()
|
||||||
{
|
{
|
||||||
|
|
||||||
//Arrange
|
//Arrange
|
||||||
|
FluentSlider<int> slider = new();
|
||||||
var childContent = "<b>render me</b>";
|
var childContent = "<b>render me</b>";
|
||||||
int position = default!;
|
int position = default!;
|
||||||
bool? hideMark = default!;
|
bool? hideMark = default!;
|
||||||
bool? disabled = default!;
|
bool? disabled = default!;
|
||||||
|
|
||||||
var cut = TestContext.RenderComponent<FluentSliderLabel<int>>(parameters => parameters
|
var cut = TestContext.RenderComponent<FluentSliderLabel<int>>(parameters => parameters
|
||||||
.Add(p => p.Position, position)
|
.Add(p => p.Position, position)
|
||||||
.Add(p => p.HideMark, hideMark)
|
.Add(p => p.HideMark, hideMark)
|
||||||
.Add(p => p.Disabled, disabled)
|
.Add(p => p.Disabled, disabled)
|
||||||
|
.AddCascadingValue(slider)
|
||||||
.AddChildContent(childContent)
|
.AddChildContent(childContent)
|
||||||
);
|
);
|
||||||
//Act
|
//Act
|
|
@ -1,4 +0,0 @@
|
||||||
|
|
||||||
<fluent-slider-label position="0" blazor:elementreference="xxx">
|
|
||||||
<b>render me</b>
|
|
||||||
</fluent-slider-label>
|
|
Загрузка…
Ссылка в новой задаче