Skip to content

Commit 0a41643

Browse files
authored
[List] Add an OptionTitle attribute (#4147)
* Add Option Title attribute * Add OptionTitle * Update Action YAML
1 parent c9fe1ce commit 0a41643

8 files changed

Lines changed: 46 additions & 3 deletions

File tree

.github/workflows/build-core-lib.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
- name: Report Generator
135135
uses: danielpalme/ReportGenerator-GitHub-Action@5.2.4
136136
with:
137-
reports: '**/coverage.cobertura.xml;**/coverage.net8.0.cobertura.xml;**/coverage.net9.0.cobertura.xml;**/coverage.net10.0.cobertura.xml'
137+
reports: '**/coverage.cobertura.xml;**/coverage.*.cobertura.xml'
138138
targetdir: 'CoverageReports'
139139
title: 'Unit Tests Code Coverage'
140140
classfilters: '-Microsoft.FluentUI.AspNetCore.Components.DesignTokens.*'

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6298,6 +6298,11 @@
62986298
Called whenever the selection changed.
62996299
</summary>
63006300
</member>
6301+
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentOption`1.Title">
6302+
<summary>
6303+
Gets or sets the title tooltip of this option.
6304+
</summary>
6305+
</member>
63016306
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentOption`1.OnClickHandlerAsync">
63026307
<summary />
63036308
</member>
@@ -6481,6 +6486,12 @@
64816486
Gets or sets the function used to determine if an option is initially selected.
64826487
</summary>
64836488
</member>
6489+
<member name="P:Microsoft.FluentUI.AspNetCore.Components.ListComponentBase`1.OptionTitle">
6490+
<summary>
6491+
Gets or sets the function used to determine the option tooltip (title).
6492+
If null is returned, then no title is displayed.
6493+
</summary>
6494+
</member>
64846495
<member name="P:Microsoft.FluentUI.AspNetCore.Components.ListComponentBase`1.OptionComparer">
64856496
<summary>
64866497
Gets or sets the <see cref="T:System.Collections.Generic.IEqualityComparer`1"/> used to determine if an option is already added to the internal list.
@@ -6564,6 +6575,9 @@
65646575
<member name="M:Microsoft.FluentUI.AspNetCore.Components.ListComponentBase`1.GetOptionValue(`0)">
65656576
<summary />
65666577
</member>
6578+
<member name="M:Microsoft.FluentUI.AspNetCore.Components.ListComponentBase`1.GetOptionTitle(`0)">
6579+
<summary />
6580+
</member>
65676581
<member name="M:Microsoft.FluentUI.AspNetCore.Components.ListComponentBase`1.GetOptionText(`0)">
65686582
<summary />
65696583
</member>

examples/Demo/Shared/Pages/List/Listbox/Examples/ListboxManual.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<FluentListbox TOption="string" ValueChanged="@(e => listboxValue = e)">
2-
<FluentOption>This option has no value</FluentOption>
2+
<FluentOption Title="With a tooltip">This option has no value</FluentOption>
33
<FluentOption Value="Item 1" Disabled="true">This option is disabled</FluentOption>
44
<FluentOption Value="Item 2">This option has a value</FluentOption>
55
<FluentOption Value="Item 3">
@@ -17,4 +17,4 @@
1717

1818
@code {
1919
string? listboxValue = "Item 4";
20-
}
20+
}

examples/Demo/Shared/Pages/List/Select/Examples/SelectDefault.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Placeholder="Make a selection..."
99
OptionValue="@(p => p.PersonId.ToString())"
1010
OptionText="@(p => p.LastName + ", " + p.FirstName)"
11+
OptionTitle="@(p => p.LastName.Length + p.FirstName.Length > 20 ? p.LastName : null)"
1112
@bind-Value="@SelectedValue"
1213
@bind-SelectedOption="@SelectedPerson" />
1314

src/Core/Components/List/FluentOption.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
style="@Style"
88
disabled="@Disabled"
99
value="@Value"
10+
title="@Title"
1011
selected="@Selected"
1112
aria-selected="@(Selected ? "true" : "false")"
1213
@onclick="@OnClickHandlerAsync"

src/Core/Components/List/FluentOption.razor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public partial class FluentOption<TOption> : FluentComponentBase, IDisposable wh
4848
[Parameter]
4949
public EventCallback<string> OnSelect { get; set; }
5050

51+
/// <summary>
52+
/// Gets or sets the title tooltip of this option.
53+
/// </summary>
54+
[Parameter]
55+
public string? Title { get; set; }
56+
5157
protected override Task OnInitializedAsync()
5258
{
5359
InternalListContext.Register(this);

src/Core/Components/List/ListComponentBase.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
{
2929
<FluentOption TOption="TOption"
3030
Value="@GetOptionValue(item)"
31+
Title="@GetOptionTitle(item)"
3132
Selected="@GetOptionSelected(item)"
3233
Disabled="@(GetOptionDisabled(item) ?? false)"
3334
OnSelect="@OnSelectCallback(item)"

src/Core/Components/List/ListComponentBase.razor.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ protected string? InternalValue
129129
[Parameter]
130130
public virtual Func<TOption, bool>? OptionSelected { get; set; }
131131

132+
/// <summary>
133+
/// Gets or sets the function used to determine the option tooltip (title).
134+
/// If null is returned, then no title is displayed.
135+
/// </summary>
136+
[Parameter]
137+
public virtual Func<TOption, string?>? OptionTitle { get; set; }
138+
132139
/// <summary>
133140
/// Gets or sets the <see cref="IEqualityComparer{T}"/> used to determine if an option is already added to the internal list.
134141
/// ⚠️ Only available when Multiple = true.
@@ -505,6 +512,19 @@ protected virtual bool GetOptionSelected(TOption item)
505512
}
506513
}
507514

515+
/// <summary />
516+
protected virtual string? GetOptionTitle(TOption? item)
517+
{
518+
if (item != null && OptionTitle != null)
519+
{
520+
return OptionTitle.Invoke(item);
521+
}
522+
else
523+
{
524+
return null;
525+
}
526+
}
527+
508528
protected virtual bool? GetOptionDisabled(TOption? item)
509529
{
510530
if (item != null)

0 commit comments

Comments
 (0)