Skip to content
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
34 changes: 33 additions & 1 deletion src/Core.Scripts/src/Components/Menu/FluentMenu.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
import { Menu, MenuList } from "@fluentui/web-components";
import { Menu, MenuItem, MenuList } from "@fluentui/web-components";
import { DotNet } from "../../d-ts/Microsoft.JSInterop";

export namespace Microsoft.FluentUI.Blazor.Components.Menu {
const menuAbortControllers = new Map<string, AbortController>();
const menuListsWithMouseOutWorkaround = new WeakSet<MenuList>();

// Closes an open submenu when the pointer leaves, even if its parent menu item retains focus.
function handleMenuListMouseOut(event: MouseEvent) {
const relatedTarget = event.relatedTarget;

for (const target of event.composedPath()) {
if (!(target instanceof MenuItem)) {
continue;
}

const submenu = target.submenu;
if (!submenu?.matches(":popover-open")) {
continue;
}

if (relatedTarget instanceof Node && target.contains(relatedTarget)) {
continue;
}

if (submenu.contains(document.activeElement)) {
continue;
}

submenu.togglePopover(false);
Comment thread
dvoituron marked this conversation as resolved.
}
}

/**
* Initializes the menu by associating it with a trigger element and setting up the necessary styles for positioning.
Expand Down Expand Up @@ -42,6 +69,11 @@ export namespace Microsoft.FluentUI.Blazor.Components.Menu {
menuList.style["position-anchor" as any] = `--anchor-${triggerId}`;
menu.slottedTriggersChanged(menu.slottedTriggers ?? [], [trigger]);

if (!menuListsWithMouseOutWorkaround.has(menuList)) {
menuList.addEventListener("mouseout", handleMenuListMouseOut);
menuListsWithMouseOutWorkaround.add(menuList);
}

menuAbortControllers.get(id)?.abort();
if (dotNetHelper) {
const abortController = new AbortController();
Expand Down
8 changes: 8 additions & 0 deletions src/Core/Components/Menu/FluentMenuList.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@
fluent-menu fluent-menu-list:not([popover]) {
display: none;
}

/* Fix #5207 */
fluent-menu-item>fluent-menu-list[slot="submenu"] {
position-try-fallbacks:
flip-inline,
flip-block,
flip-block flip-inline;
}
Comment thread
dvoituron marked this conversation as resolved.
Loading