Skip to content

Commit 5ffe060

Browse files
authored
[MenuButton] Finalize work on a11y fixes and custom button content (#4093) (#4221)
* Remove check on Text and ButtonContent being provided, change xml doc wording, * Remove redundant test
1 parent 4933136 commit 5ffe060

File tree

3 files changed

+20
-31
lines changed

3 files changed

+20
-31
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6692,6 +6692,13 @@
66926692
Gets or sets the button appearance.
66936693
</summary>
66946694
</member>
6695+
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentMenuButton.ButtonContent">
6696+
<summary>
6697+
The content to be rendered inside the button. This parameter should be supplied if you do not want to render a chevron
6698+
on the menu button.
6699+
If both <see cref="P:Microsoft.FluentUI.AspNetCore.Components.FluentMenuButton.Text"/> and ButtonContent are provided, ButtonContent will be used.
6700+
</summary>
6701+
</member>
66956702
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentMenuButton.Menu">
66966703
<summary>
66976704
Gets or sets a reference to the menu.
@@ -6706,7 +6713,8 @@
67066713
</member>
67076714
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentMenuButton.Text">
67086715
<summary>
6709-
Gets or sets the texts shown on th button.
6716+
Gets or sets the texts shown on the button.
6717+
If both Text and<see cref = "P:Microsoft.FluentUI.AspNetCore.Components.FluentMenuButton.ButtonContent" /> are provided, ButtonContent will be used.
67106718
</summary>
67116719
</member>
67126720
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentMenuButton.IconStart">
@@ -6880,7 +6888,7 @@
68806888
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentMenu.SetOpenAsync(System.Boolean)">
68816889
<summary />
68826890
</member>
6883-
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentMenu.Dispose">
6891+
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentMenu.DisposeAsync">
68846892
<summary>
68856893
Dispose this menu.
68866894
</summary>

src/Core/Components/MenuButton/FluentMenuButton.razor.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public partial class FluentMenuButton : FluentComponentBase
2929
[Parameter]
3030
public Appearance ButtonAppearance { get; set; } = Appearance.Accent;
3131

32+
/// <summary>
33+
/// The content to be rendered inside the button. This parameter should be supplied if you do not want to render a chevron
34+
/// on the menu button.
35+
/// If both <see cref="Text"/> and ButtonContent are provided, ButtonContent will be used.
36+
/// </summary>
37+
[Parameter]
38+
public RenderFragment? ButtonContent { get; set; }
39+
3240
/// <summary>
3341
/// Gets or sets a reference to the menu.
3442
/// </summary>
@@ -44,7 +52,8 @@ public partial class FluentMenuButton : FluentComponentBase
4452
public bool UseMenuService { get; set; } = true;
4553

4654
/// <summary>
47-
/// Gets or sets the texts shown on the button. This property will be ignored if <see cref="ButtonContent"/> is provided.
55+
/// Gets or sets the texts shown on the button.
56+
/// If both Text and<see cref = "ButtonContent" /> are provided, ButtonContent will be used.
4857
/// </summary>
4958
[Parameter]
5059
public string? Text { get; set; }
@@ -87,25 +96,13 @@ public partial class FluentMenuButton : FluentComponentBase
8796
[Parameter]
8897
public EventCallback<MenuChangeEventArgs> OnMenuChanged { get; set; }
8998

90-
/// <summary>
91-
/// The content to be rendered inside the button. This parameter should be supplied if you do not want to render a chevron
92-
/// on the menu button. Only one of <see cref="Text"/> or <see cref="ButtonContent"/> may be provided.
93-
/// </summary>
94-
[Parameter]
95-
public RenderFragment? ButtonContent { get; set; }
96-
9799
protected override void OnInitialized()
98100
{
99101
_buttonId = Identifier.NewId();
100102
}
101103

102104
protected override void OnParametersSet()
103105
{
104-
if (Text is not null && ButtonContent is not null)
105-
{
106-
throw new ArgumentException($"Only one of the parameters {nameof(Text)} or {nameof(ButtonContent)} can be provided.");
107-
}
108-
109106
_iconColor = ButtonAppearance == Appearance.Accent ? Color.Fill : Color.FillInverse;
110107
}
111108

tests/Core/_ToDo/MenuButton/FluentMenuButtonTests.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,6 @@ public void FluentMenuButton_IconStart()
8080
cut.Verify();
8181
}
8282

83-
[Fact]
84-
public void FluentMenuButton_Throws_IfBothTextAndButtonContentAreSet()
85-
{
86-
Assert.Throws<ArgumentException>(() =>
87-
{
88-
TestContext.RenderComponent<FluentMenuButton>(parameters => parameters
89-
.Add(p => p.Text, "Button Text")
90-
.Add<RenderFragment>(p => p.ButtonContent, builder =>
91-
{
92-
builder.OpenComponent<FluentMenuItem>(0);
93-
builder.AddAttribute(1, "Text", "Menu Item 1");
94-
builder.CloseComponent();
95-
})
96-
);
97-
});
98-
}
9983

10084
[Fact]
10185
public void FluentMenuButton_Renders_ButtonContent()

0 commit comments

Comments
 (0)