@@ -117,6 +117,17 @@ public class PrivilegeLink : NavLink
117117 [ Parameter ]
118118 public string ? Qualifier { get ; set ; }
119119
120+ /// <summary>
121+ /// Gets or sets a value indicating whether links should be hidden when the user
122+ /// lacks the required permissions instead of being displayed in a disabled state.
123+ /// </summary>
124+ /// <value>
125+ /// <c>true</c> to hide the link when permission is denied; <c>false</c> to show
126+ /// the link in a disabled state. Defaults to <c>false</c>.
127+ /// </value>
128+ [ Parameter ]
129+ public bool HideForbidden { get ; set ; }
130+
120131 /// <summary>
121132 /// Gets a value indicating whether the user has permission to access this navigation link.
122133 /// </summary>
@@ -203,9 +214,22 @@ protected override void OnParametersSet()
203214 /// </remarks>
204215 protected override void BuildRenderTree ( RenderTreeBuilder builder )
205216 {
206- if ( ! HasPermission )
217+ // Do not render if the user does not have permission and HideForbidden is true
218+ if ( HideForbidden && ! HasPermission )
207219 return ;
208220
209- base . BuildRenderTree ( builder ) ;
221+ // render normally if we have permission
222+ if ( HasPermission )
223+ {
224+ base . BuildRenderTree ( builder ) ;
225+ return ;
226+ }
227+
228+ // render a span with the same attributes if no permission
229+ builder . OpenElement ( 0 , "span" ) ;
230+ builder . AddMultipleAttributes ( 1 , AdditionalAttributes ) ;
231+ builder . AddAttribute ( 2 , "class" , CssClass ) ;
232+ builder . AddContent ( 3 , ChildContent ) ;
233+ builder . CloseElement ( ) ;
210234 }
211235}
0 commit comments