@@ -1195,6 +1195,7 @@ func renderDrawer(page : &mut HtmlPage) {
11951195}
11961196
11971197func renderMenu (page : &mut HtmlPage) {
1198+ dropdownInit (page, "dropdown-demo" )
11981199 #html {
11991200 < div class="docs-section" id="docs-menu" data-comp="menu" >
12001201 < h1 class="docs-component-title" > Menu< /h1>
@@ -1203,19 +1204,15 @@ func renderMenu(page : &mut HtmlPage) {
12031204 < thead>< tr>< th> Prop< /th>< th> Type< /th>< th> Default< /th>< th> Description< /th>< /tr>< /thead>
12041205 < tbody>
12051206 < tr>< td class="docs-prop-name" > children< /td>< td class="docs-prop-type" > *char< /td>< td class="docs-prop-default" > -< /td>< td class="docs-prop-desc" > Menu items< /td>< /tr>
1206- < tr>< td class="docs-prop-name" > open< /td>< td class="docs-prop-type" > bool< /td>< td class="docs-prop-default" > false< /td>< td class="docs-prop-desc" > Open state< /td>< /tr>
12071207 < /tbody>
12081208 < /table>
12091209 < div class="docs-demo-box" >
12101210 < div class="docs-demo-label" > Live Demo< /div>
1211- < div id="menu-demo" style="position:relative;display:inline-block;" >
1212- < Button onclick="toggleMenu()" id="menu-trigger" > Open Menu< /Button>
1213- < Menu id="menu-dropdown" style="display:none;position:absolute;top:100%;left:0;margin-top:0.5rem;z-index:10;" >
1214- < MenuItem> Profile< /MenuItem>
1215- < MenuItem> Settings< /MenuItem>
1216- < MenuItem> Logout< /MenuItem>
1217- < /Menu>
1218- < /div>
1211+ < Dropdown id="dropdown-demo" trigger="Open Menu" >
1212+ < DropdownItem> Profile< /DropdownItem>
1213+ < DropdownItem> Settings< /DropdownItem>
1214+ < DropdownItem> Logout< /DropdownItem>
1215+ < /Dropdown>
12191216 < /div>
12201217 < /div>
12211218 }
@@ -1293,7 +1290,7 @@ func renderSnackbar(page : &mut HtmlPage) {
12931290 < div class="docs-demo-box" >
12941291 < div class="docs-demo-label" > Live Demo< /div>
12951292 < div id="snackbar-demo" style="position:relative;display:flex;flex-direction:column;gap:1rem;align-items:flex-start;" >
1296- < Button onclick= "showSnackbar() "> Show Snackbar< /Button>
1293+ < Button id= "snackbar-trigger "> Show Snackbar< /Button>
12971294 < Snackbar id="snackbar-toast" style="display:none;" > Item saved successfully!< /Snackbar>
12981295 < /div>
12991296 < /div>
@@ -1601,22 +1598,26 @@ func SetupComponentNav(page : &mut HtmlPage) {
16011598 window.addEventListener('hashchange', function() {
16021599 showComponent(window.location.hash.slice(1) || 'headings');
16031600 });
1604- window.toggleMenu = function() {
1605- var m = document.getElementById('menu-dropdown');
1606- if (m) m.style.display = m.style.display === 'none' ? '' : 'none';
1607- };
1608- window.showSnackbar = function() {
1609- var s = document.getElementById('snackbar-toast');
1610- if (s) {
1611- s.style.display = '';
1612- setTimeout(function(){ s.style.display = 'none'; }, 3000);
1601+ document.addEventListener('DOMContentLoaded', function() {
1602+ var menuTrigger = document.getElementById('menu-trigger');
1603+ var menuDropdown = document.getElementById('menu-dropdown');
1604+ if (menuTrigger && menuDropdown) {
1605+ menuTrigger.addEventListener('click', function() {
1606+ menuDropdown.style.display = menuDropdown.style.display === 'none' ? '' : 'none';
1607+ });
1608+ document.addEventListener('click', function(e) {
1609+ if (!menuTrigger.contains(e.target) && !menuDropdown.contains(e.target)) {
1610+ menuDropdown.style.display = 'none';
1611+ }
1612+ });
16131613 }
1614- };
1615- document.addEventListener('click', function(e) {
1616- var m = document.getElementById('menu-dropdown');
1617- var t = document.getElementById('menu-trigger');
1618- if (m && t && !t.contains(e.target) && !m.contains(e.target)) {
1619- m.style.display = 'none';
1614+ var snackbarTrigger = document.getElementById('snackbar-trigger');
1615+ var snackbarToast = document.getElementById('snackbar-toast');
1616+ if (snackbarTrigger && snackbarToast) {
1617+ snackbarTrigger.addEventListener('click', function() {
1618+ snackbarToast.style.display = '';
1619+ setTimeout(function(){ snackbarToast.style.display = 'none'; }, 3000);
1620+ });
16201621 }
16211622 });
16221623 }());
0 commit comments