Skip to content

Commit

Permalink
refactor(menu-item): add null check of the Id parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
desmondinho committed Feb 20, 2025
1 parent 0f8127f commit 5e40b2f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

@code {
private ThemeColor _color = ThemeColor.Default;
private MenuVariant _variant = MenuVariant.Solid;

private Task TriggerAsync( string id )
{
Expand All @@ -57,7 +56,7 @@
MenuVariant.Flat => Variant.Flat,
MenuVariant.Shadow => Variant.Shadow,
MenuVariant.Light => Variant.Light,
_ => Variant.Solid
_ => throw new NotSupportedException()
};
}
}
6 changes: 6 additions & 0 deletions src/LumexUI/Components/Menu/MenuItem.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ protected override void OnInitialized()
/// <inheritdoc />
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 );
Expand Down

0 comments on commit 5e40b2f

Please sign in to comment.