From 5e40b2f53d6e66d53629fdf45be42b04c55fd535 Mon Sep 17 00:00:00 2001 From: desmondinho Date: Thu, 20 Feb 2025 20:52:30 +0200 Subject: [PATCH] refactor(menu-item): add null check of the `Id` parameter --- .../Pages/Components/Dropdown/Examples/ColorsVariants.razor | 3 +-- src/LumexUI/Components/Menu/MenuItem.razor.cs | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/LumexUI.Docs.Client/Pages/Components/Dropdown/Examples/ColorsVariants.razor b/docs/LumexUI.Docs.Client/Pages/Components/Dropdown/Examples/ColorsVariants.razor index 5b47fa62..fb84af1a 100644 --- a/docs/LumexUI.Docs.Client/Pages/Components/Dropdown/Examples/ColorsVariants.razor +++ b/docs/LumexUI.Docs.Client/Pages/Components/Dropdown/Examples/ColorsVariants.razor @@ -41,7 +41,6 @@ @code { private ThemeColor _color = ThemeColor.Default; - private MenuVariant _variant = MenuVariant.Solid; private Task TriggerAsync( string id ) { @@ -57,7 +56,7 @@ MenuVariant.Flat => Variant.Flat, MenuVariant.Shadow => Variant.Shadow, MenuVariant.Light => Variant.Light, - _ => Variant.Solid + _ => throw new NotSupportedException() }; } } \ No newline at end of file diff --git a/src/LumexUI/Components/Menu/MenuItem.razor.cs b/src/LumexUI/Components/Menu/MenuItem.razor.cs index 68b05cc0..916eb07a 100644 --- a/src/LumexUI/Components/Menu/MenuItem.razor.cs +++ b/src/LumexUI/Components/Menu/MenuItem.razor.cs @@ -116,6 +116,12 @@ protected override void OnInitialized() /// protected override void OnParametersSet() { + if( Id is null ) + { + throw new InvalidOperationException( + $"{GetType()} requires a value for the {nameof( Id )} parameter." ); + } + _disabled = Disabled || Menu.DisabledItems?.Contains( Id ) is true; var menuItem = Styles.MenuItem.Style( TwVariant );