Skip to content
Discussion options

You must be logged in to vote

I dug into packages/@headlessui-react/src/hooks/use-handle-toggle.tsx, which is what MenuButton actually wires up instead of a plain onClick:

export function useHandleToggle(cb) {
  const pointerTypeRef = useRef<'touch' | 'mouse' | 'pen' | null>(null);

  const handlePointerDown = useEvent((event) => {
    pointerTypeRef.current = event.pointerType;
    if (event.pointerType !== 'mouse') return;
    // ...
    cb(event);
  });

  const handleClick = useEvent((event) => {
    if (pointerTypeRef.current === 'mouse') return; // <-- this
    // ...
    cb(event);
  });

  return { onPointerDown: handlePointerDown, onClick: handleClick };
}

The toggle logic for a real mouse click actually runs…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by dd-jonas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3705 on April 25, 2025 09:18.