Skip to content

Commit

Permalink
fix(menubar): dont auto open when closed from trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 committed Feb 8, 2024
1 parent d910cee commit e063e52
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/core/src/menu/menu-trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,35 @@ export function MenuTrigger(props: MenuTriggerProps) {
optionalMenubarContext.setLastValue(key);
}

const handleClick = () => {
// When opened by click, automatically focus Menubar menus
optionalMenubarContext?.setAutoFocusMenu(true);

// Don't auto focus element for Menubar
if (optionalMenubarContext !== undefined) context.toggle(false);
else context.toggle(true);

if (optionalMenubarContext !== undefined && !context.isOpen() && optionalMenubarContext.value() === key) {
optionalMenubarContext.closeMenu();
}
};

const onPointerDown: JSX.EventHandlerUnion<any, PointerEvent> = (e) => {
callHandler(e, local.onPointerDown);

e.currentTarget.dataset.pointerType = e.pointerType;

// For consistency with native, open the select on mouse down (main button), but touch up.
if (!local.disabled && e.pointerType !== "touch" && e.button === 0) {
// When opened by click, automatically focus Menubar menus
optionalMenubarContext?.setAutoFocusMenu(true);

// Don't auto focus element for Menubar
if (optionalMenubarContext !== undefined) context.toggle(false);
else context.toggle(true);
handleClick();
}
};

const onClick: JSX.EventHandlerUnion<any, MouseEvent> = (e) => {
callHandler(e, local.onClick);

if (!local.disabled) {
if (e.currentTarget.dataset.pointerType === "touch") context.toggle(true);
if (e.currentTarget.dataset.pointerType === "touch") handleClick();
}
};

Expand Down

0 comments on commit e063e52

Please sign in to comment.