Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1185: NavMenu Collapse button behavior in SRR only woks once #1191

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/Core/Components/NavMenu/FluentNavMenu.razor.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
export function onUpdate() {
export function onLoad() {
for (let expander of document.getElementsByClassName("expander")) {
if (expander) {
const origStyle = expander.parentElement.style.cssText;
expander.addEventListener('click', () => toggleMenuExpandedAsync(expander, origStyle));
expander.parentElement.addEventListener('keydown', (ev) => handleMenuExpanderKeyDownAsync(expander, origStyle, ev));
expander.addEventListener('click', (ev) => toggleMenuExpandedAsync(expander, origStyle, ev), true);
expander.parentElement.addEventListener('keydown', (ev) => handleMenuExpanderKeyDownAsync(expander, origStyle, ev), true);
}
}

}
export function onUpdate() {
for (let element of document.getElementsByClassName("fluent-nav-group")) {
attachEventHandlers(element);
}
}

function attachEventHandlers(element) {
let navlink = element.getElementsByClassName("fluent-nav-link")[0];
if (!navlink.href) {
Expand Down Expand Up @@ -71,7 +73,7 @@ function handleMenuExpanderKeyDownAsync(element, origStyle, event) {
switch (event.code) {
case "NumpadEnter":
case "Enter":
toggleMenuExpandedAsync(element, origStyle);
toggleMenuExpandedAsync(element, origStyle, event);
break;
case "NumpadArrowRight":
case "ArrowRight":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="navmenu">
<input type="checkbox" id="navmenu-toggle" />
<nav class="sitenav" aria-labelledby="main-menu" onclick="document.getElementById('navmenu-toggle').click();">
<FluentNavMenu Id="main-menu" Width="250" Title="Navigation menu" @bind-Expanded="expanded">
<FluentNavMenu Id="main-menu" Collapsible="true" Width="250" Title="Navigation menu" @bind-Expanded="expanded">
<FluentNavLink Href="/" Match="NavLinkMatch.All" Icon="@(new Icons.Regular.Size20.Home())" IconColor="Color.Accent">Home</FluentNavLink>
<FluentNavLink Href="weather" Icon="@(new Icons.Regular.Size20.WeatherPartlyCloudyDay())" IconColor="Color.Accent">Weather</FluentNavLink>
<FluentNavLink Href="test" Icon="@(new Icons.Regular.Size20.Beaker())" IconColor="Color.Accent">Test</FluentNavLink>
Expand Down