diff --git a/src/Core/Components/Base/IFluentControlStyle.cs b/src/Core/Components/Base/IFluentControlStyle.cs index 9157ce5f03..9f8ee17388 100644 --- a/src/Core/Components/Base/IFluentControlStyle.cs +++ b/src/Core/Components/Base/IFluentControlStyle.cs @@ -21,7 +21,7 @@ namespace Microsoft.FluentUI.AspNetCore.Components; * { * if (firstRender && !string.IsNullOrEmpty(ControlStyle)) * { - * await JSRuntime.InvokeVoidAsync("Microsoft.FluentUI.Blazor.Utilities.Attributes.applyShadowStyle", Element, ".control", ControlStyle); + * await JSRuntime.InvokeVoidAsync("Microsoft.FluentUI.Blazor.Utilities.Attributes.applyShadowStyle", Element, ":host .control", ControlStyle); * } * } * diff --git a/src/Core/Components/List/FluentSelect.razor b/src/Core/Components/List/FluentSelect.razor index d11f546b8b..45a1e04676 100644 --- a/src/Core/Components/List/FluentSelect.razor +++ b/src/Core/Components/List/FluentSelect.razor @@ -7,7 +7,8 @@ - [CascadingTypeParameter(nameof(TValue))] -public partial class FluentSelect : FluentListBase +public partial class FluentSelect : FluentListBase, IFluentControlStyle, IFluentComponentElementBase { /// public FluentSelect(LibraryConfiguration configuration) : base(configuration) { } @@ -41,6 +41,14 @@ public FluentSelect(LibraryConfiguration configuration) : base(configuration) { [Parameter] public ListSize? Size { get; set; } + /// + [Parameter] + public ElementReference Element { get; set; } + + /// + [Parameter] + public string? ControlStyle { get; set; } + /// protected override async Task OnAfterRenderAsync(bool firstRender) { @@ -50,6 +58,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender) // This method don't change the SelectedItems and Value properties. var defaultText = Value is TOption option ? base.GetOptionText(option) : ""; await JSRuntime.InvokeFluentVoidAsync("Microsoft.FluentUI.Blazor.Components.Select.Initialize", Id, defaultText); + + if (!string.IsNullOrEmpty(ControlStyle)) + { + await JSRuntime.InvokeFluentVoidAsync("Microsoft.FluentUI.Blazor.Utilities.Attributes.applyShadowStyle", Element, ":host .control", ControlStyle); + } } await base.OnAfterRenderAsync(firstRender); diff --git a/src/Core/Components/NumberInput/FluentNumberInput.razor.cs b/src/Core/Components/NumberInput/FluentNumberInput.razor.cs index 981cb9b5a7..5b015d1ddd 100644 --- a/src/Core/Components/NumberInput/FluentNumberInput.razor.cs +++ b/src/Core/Components/NumberInput/FluentNumberInput.razor.cs @@ -188,7 +188,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) if (!string.IsNullOrEmpty(ControlStyle)) { - await JSRuntime.InvokeVoidAsync("Microsoft.FluentUI.Blazor.Utilities.Attributes.applyShadowStyle", Element, ".control", ControlStyle); + await JSRuntime.InvokeVoidAsync("Microsoft.FluentUI.Blazor.Utilities.Attributes.applyShadowStyle", Element, ":host .control", ControlStyle); } } } diff --git a/src/Core/Components/TextArea/FluentTextArea.razor.cs b/src/Core/Components/TextArea/FluentTextArea.razor.cs index 6d6623018d..699d581774 100644 --- a/src/Core/Components/TextArea/FluentTextArea.razor.cs +++ b/src/Core/Components/TextArea/FluentTextArea.razor.cs @@ -179,7 +179,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) if (!string.IsNullOrEmpty(ControlStyle)) { - await JSRuntime.InvokeVoidAsync("Microsoft.FluentUI.Blazor.Utilities.Attributes.applyShadowStyle", Element, ".control", ControlStyle); + await JSRuntime.InvokeVoidAsync("Microsoft.FluentUI.Blazor.Utilities.Attributes.applyShadowStyle", Element, ":host .control", ControlStyle); } } } diff --git a/src/Core/Components/TextInput/FluentTextInput.razor.cs b/src/Core/Components/TextInput/FluentTextInput.razor.cs index a71dcb92a2..acf0560e6c 100644 --- a/src/Core/Components/TextInput/FluentTextInput.razor.cs +++ b/src/Core/Components/TextInput/FluentTextInput.razor.cs @@ -239,7 +239,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) if (!string.IsNullOrEmpty(ControlStyle)) { - await JSRuntime.InvokeVoidAsync("Microsoft.FluentUI.Blazor.Utilities.Attributes.applyShadowStyle", Element, ".control", ControlStyle); + await JSRuntime.InvokeVoidAsync("Microsoft.FluentUI.Blazor.Utilities.Attributes.applyShadowStyle", Element, ":host .control", ControlStyle); } } } diff --git a/tests/Core/Components/List/FluentSelectTests.razor b/tests/Core/Components/List/FluentSelectTests.razor index cb7600dc4c..49308a7031 100644 --- a/tests/Core/Components/List/FluentSelectTests.razor +++ b/tests/Core/Components/List/FluentSelectTests.razor @@ -318,6 +318,20 @@ Assert.Equal(expected, attribute); } + [Fact] + public void FluentSelect_ControlStyle_AppliesStyleToInternalControl() + { + // Arrange and Act + Render(@); + + // Assert + var invocation = JSInterop.VerifyInvoke("Microsoft.FluentUI.Blazor.Utilities.Attributes.applyShadowStyle"); + Assert.Equal(3, invocation.Arguments.Count); + Assert.IsType(invocation.Arguments[0]); + Assert.Equal(":host .control", invocation.Arguments[1]); + Assert.Equal("color: red;", invocation.Arguments[2]); + } + [Theory] [InlineData("1", 1, null)] [InlineData("abc", 0, "The 'Unknown Bound Field' field is not valid.")] diff --git a/tests/Core/Components/Number/FluentNumberTests.razor b/tests/Core/Components/Number/FluentNumberTests.razor index 23bbd64d11..ced9319dab 100644 --- a/tests/Core/Components/Number/FluentNumberTests.razor +++ b/tests/Core/Components/Number/FluentNumberTests.razor @@ -413,7 +413,7 @@ var invocation = JSInterop.VerifyInvoke("Microsoft.FluentUI.Blazor.Utilities.Attributes.applyShadowStyle"); Assert.Equal(3, invocation.Arguments.Count); Assert.IsType(invocation.Arguments[0]); - Assert.Equal(".control", invocation.Arguments[1]); + Assert.Equal(":host .control", invocation.Arguments[1]); Assert.Equal("color: red;", invocation.Arguments[2]); } diff --git a/tests/Core/Components/TextArea/FluentTextAreaTests.razor b/tests/Core/Components/TextArea/FluentTextAreaTests.razor index 728c81f1c6..f7d05fa353 100644 --- a/tests/Core/Components/TextArea/FluentTextAreaTests.razor +++ b/tests/Core/Components/TextArea/FluentTextAreaTests.razor @@ -208,7 +208,7 @@ var invocation = JSInterop.VerifyInvoke("Microsoft.FluentUI.Blazor.Utilities.Attributes.applyShadowStyle"); Assert.Equal(3, invocation.Arguments.Count); Assert.IsType(invocation.Arguments[0]); - Assert.Equal(".control", invocation.Arguments[1]); + Assert.Equal(":host .control", invocation.Arguments[1]); Assert.Equal("color: red;", invocation.Arguments[2]); } } diff --git a/tests/Core/Components/TextInput/FluentTextInputTests.razor b/tests/Core/Components/TextInput/FluentTextInputTests.razor index b37582eb77..575a2796a1 100644 --- a/tests/Core/Components/TextInput/FluentTextInputTests.razor +++ b/tests/Core/Components/TextInput/FluentTextInputTests.razor @@ -242,7 +242,7 @@ var invocation = JSInterop.VerifyInvoke("Microsoft.FluentUI.Blazor.Utilities.Attributes.applyShadowStyle"); Assert.Equal(3, invocation.Arguments.Count); Assert.IsType(invocation.Arguments[0]); - Assert.Equal(".control", invocation.Arguments[1]); + Assert.Equal(":host .control", invocation.Arguments[1]); Assert.Equal("color: red;", invocation.Arguments[2]); }