1+ @namespace MudBlazor.StaticInput
2+
3+ @inherits MudNavGroup
4+
5+ @{
6+ base .BuildRenderTree (__builder );
7+ }
8+
9+ @code {
10+ private string _elementId = string .Empty ;
11+
12+ protected override void OnParametersSet ()
13+ {
14+ UserAttributes [" data-static-component" ] = true ;
15+ UserAttributes [" data-static-id" ] = _elementId ;
16+
17+ base .OnParametersSet ();
18+ }
19+
20+ protected override void OnInitialized ()
21+ {
22+ _elementId = Guid .NewGuid ().ToString ()[.. 8 ];
23+
24+ base .OnInitialized ();
25+ }
26+ }
27+
28+ @if (IsStatic ()) {
29+ < script >
30+ (function () {
31+ document .addEventListener ('DOMContentLoaded' , () => {
32+ const button = document .querySelector ('[data-static-id="@_elementId"] button' );
33+
34+ if (button ) {
35+ button .addEventListener ('click' , (event ) => {
36+ const navElement = event .target .closest ('nav' );
37+ const collapseContainer = navElement .querySelector ('.mud-collapse-container' );
38+ const expandIcon = navElement .querySelector ('.mud-nav-link-expand-icon' );
39+
40+ if (! collapseContainer || ! expandIcon ) {
41+ console .warn (" Missing required elements for toggling" );
42+ return ;
43+ }
44+
45+ // Check current state
46+ const isExpanded = button .getAttribute ('aria-expanded' ) == = " true" ;
47+
48+ // Toggle classes for collapse container
49+ collapseContainer .classList .toggle ('mud-collapse-entered' , ! isExpanded );
50+ collapseContainer .classList .toggle ('mud-navgroup-collapse' , true );
51+ collapseContainer .classList .remove ('mud-collapse-entering' );
52+ collapseContainer .setAttribute ('aria-hidden' , isExpanded );
53+
54+ // Toggle classes for expand icon
55+ expandIcon .classList .toggle ('mud-transform' , ! isExpanded );
56+
57+ // Update aria-expanded on the button
58+ button .setAttribute ('aria-expanded' , ! isExpanded );
59+ });
60+ }
61+ });
62+ })();
63+ < / script >
64+ }
0 commit comments