From a43b7c3d4ef25ae879d37b95af6c1578b5e2fec8 Mon Sep 17 00:00:00 2001 From: "Steven T. Cramer" Date: Thu, 16 May 2024 22:33:00 +0700 Subject: [PATCH] [Lists] Change Option.Text to `string?` (#2063) * In Option change the type of `Text` to string? If it is TType it only adds value for TType of string otherwise it makes no sense if Text is some Ojbect. * Update the demo apps to use Text as a string. * Use string literal instead of ToString. * Now we can remove redundant .ToString --------- Co-authored-by: Vincent Baaij --- .../Combobox/Examples/ComboboxFromListOfOptions.razor | 10 +++++----- .../Listbox/Examples/ListboxFromListOfOptions.razor | 8 ++++---- .../List/Select/Examples/SelectFromListOfOptions.razor | 8 ++++---- src/Core/Components/List/Option.cs | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/Demo/Shared/Pages/List/Combobox/Examples/ComboboxFromListOfOptions.razor b/examples/Demo/Shared/Pages/List/Combobox/Examples/ComboboxFromListOfOptions.razor index 570b259522..1f542e3a50 100644 --- a/examples/Demo/Shared/Pages/List/Combobox/Examples/ComboboxFromListOfOptions.razor +++ b/examples/Demo/Shared/Pages/List/Combobox/Examples/ComboboxFromListOfOptions.razor @@ -20,8 +20,8 @@ @@ -48,9 +48,9 @@ List> intOptions = new() { - { new Option { Value = 1, Text = 1, Disabled = true } }, - { new Option { Value = 2, Text = 2 } }, - { new Option { Value = 3, Text = 3 } } + { new Option { Value = 1, Text = "1", Disabled = true } }, + { new Option { Value = 2, Text = "2" } }, + { new Option { Value = 3, Text = "3" } } }; } \ No newline at end of file diff --git a/examples/Demo/Shared/Pages/List/Listbox/Examples/ListboxFromListOfOptions.razor b/examples/Demo/Shared/Pages/List/Listbox/Examples/ListboxFromListOfOptions.razor index c409c70d1c..a28be59f1a 100644 --- a/examples/Demo/Shared/Pages/List/Listbox/Examples/ListboxFromListOfOptions.razor +++ b/examples/Demo/Shared/Pages/List/Listbox/Examples/ListboxFromListOfOptions.razor @@ -16,7 +16,7 @@ > intOptions = new() { - { new Option { Value = 1, Text = 1, Disabled = true } }, - { new Option { Value = 2, Text = 2 } }, - { new Option { Value = 3, Text = 3 } } + { new Option { Value = 1, Text = "1", Disabled = true } }, + { new Option { Value = 2, Text = "2" } }, + { new Option { Value = 3, Text = "3" } } }; } \ No newline at end of file diff --git a/examples/Demo/Shared/Pages/List/Select/Examples/SelectFromListOfOptions.razor b/examples/Demo/Shared/Pages/List/Select/Examples/SelectFromListOfOptions.razor index e2b6d9c792..5a65511fb5 100644 --- a/examples/Demo/Shared/Pages/List/Select/Examples/SelectFromListOfOptions.razor +++ b/examples/Demo/Shared/Pages/List/Select/Examples/SelectFromListOfOptions.razor @@ -15,7 +15,7 @@

Note that the second option in the list is automatically highlighted but it has NOT been selected. It's just the first item in the list available for selection

> intOptions = new() { - { new Option { Value = 1, Text = 1, Disabled = true, Icon = (new Icons.Regular.Size24.NumberCircle1(), Color.Neutral, "start" ) } }, - { new Option { Value = 2, Text = 2, Icon = (new Icons.Regular.Size24.NumberCircle2(), Color.Neutral, "end" ) } }, - { new Option { Value = 3, Text = 3, Icon = (new Icons.Regular.Size24.NumberCircle3(), Color.Neutral, "start" ) } } + { new Option { Value = 1, Text = "1", Disabled = true, Icon = (new Icons.Regular.Size24.NumberCircle1(), Color.Neutral, "start" ) } }, + { new Option { Value = 2, Text = "2", Icon = (new Icons.Regular.Size24.NumberCircle2(), Color.Neutral, "end" ) } }, + { new Option { Value = 3, Text = "3", Icon = (new Icons.Regular.Size24.NumberCircle3(), Color.Neutral, "start" ) } } }; } diff --git a/src/Core/Components/List/Option.cs b/src/Core/Components/List/Option.cs index e392bf6844..f93e08c458 100644 --- a/src/Core/Components/List/Option.cs +++ b/src/Core/Components/List/Option.cs @@ -4,7 +4,7 @@ public class Option : IOptionIcon { public TType? Value { get; set; } - public TType? Text { get; set; } + public string? Text { get; set; } public (Icon Value, Color? Color, string? Slot)? Icon { get; set; }