Skip to content

Conversation

@jtomaszewski
Copy link
Contributor

Summary

The Menu component's trigger function signature declares a second argument state: { open: boolean } (see types.ts), but the implementation never actually passed it. This caused the trigger to always receive undefined for the state argument.

The fix: Add { open: state.isOpen } as the second argument to the trigger call in updatedTrigger().

Problem

When using the Menu component with a trigger that needs to display different UI based on whether the menu is open or closed, the state.open property was always undefined:

<Menu
  trigger={(props, state) => (
    <Button {...props}>
      {/* state.open is always undefined - BUG */}
      {state?.open ? 'Close' : 'Open'}
    </Button>
  )}
  items={items}
/>

Root Cause

In packages/gluestack-core/src/menu/creator/Menu.tsx, the updatedTrigger function only passed the props object:

// Before (bug)
const updatedTrigger = () => {
  return trigger({
    ...menuTriggerProps,
    onPress: handleOpen,
    ref: triggerRef,
  });
};

Fix

Pass the state object as the second argument to match the declared type signature:

// After (fix)
const updatedTrigger = () => {
  return trigger(
    {
      ...menuTriggerProps,
      onPress: handleOpen,
      ref: triggerRef,
    },
    { open: state.isOpen }
  );
};

Test Plan

  • Verified fix with unit tests that check state.open is true when menu is open and false when closed
  • Tested that state is preserved correctly across parent re-renders caused by async data

🤖 Generated with Claude Code

The Menu component's trigger function signature declares a second argument
`state: { open: boolean }` but the implementation never passed it.

This caused the trigger to always receive undefined for the state,
breaking use cases where triggers need to display different UI based on
whether the menu is open or closed.

The fix adds `{ open: state.isOpen }` as the second argument to the trigger
call in the updatedTrigger function.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant