Skip to content

Commit

Permalink
fix(menu): open link menu triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 committed May 3, 2024
1 parent a790c1a commit 20bceab
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/core/src/menu/menu-trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import {
JSX,
ValidComponent,
createEffect,
createMemo,
onCleanup,
splitProps,
} from "solid-js";

import * as Button from "../button";
import { useOptionalMenubarContext } from "../menubar/menubar-context";
import { PolymorphicProps } from "../polymorphic";
import { createTagName } from "../primitives/create-tag-name";
import { MenuDataSet, useMenuContext } from "./menu-context";
import { useMenuRootContext } from "./menu-root-context";

Expand Down Expand Up @@ -107,6 +109,17 @@ export function MenuTrigger<T extends ValidComponent = "button">(
optionalMenubarContext.setLastValue(key);
}

const tagName = createTagName(
() => context.triggerRef(),
() => "button",
);

const isNativeLink = createMemo(() => {
return (
tagName() === "a" && context.triggerRef()?.getAttribute("href") != null
);
});

const handleClick = () => {
// When opened by click, automatically focus Menubar menus
optionalMenubarContext?.setAutoFocusMenu(true);
Expand Down Expand Up @@ -152,6 +165,14 @@ export function MenuTrigger<T extends ValidComponent = "button">(
return;
}

if (isNativeLink()) {
switch (e.key) {
case "Enter":
case " ":
return;
}
}

// For consistency with native, open the menu on key down.
switch (e.key) {
case "Enter":
Expand Down

0 comments on commit 20bceab

Please sign in to comment.