Skip to content

[ BUG ] Dropdown not working in headerRight #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
aramis-it opened this issue Mar 19, 2025 · 3 comments
Open

[ BUG ] Dropdown not working in headerRight #364

aramis-it opened this issue Mar 19, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@aramis-it
Copy link

aramis-it commented Mar 19, 2025

<Stack
      screenOptions={{
        headerRight: () => (
          <Dropdown />              // dropdown component as in Doc
        ),
      }}
    />
@aramis-it aramis-it added the bug Something isn't working label Mar 19, 2025
@mrzachnugent
Copy link
Owner

Hey @aramis-it , it seems like you found the fix from your comment here: #302 (comment)

If you are having a problem with the onPressIn for the dropdown-menu, you can trigger it programmatically as shown here: https://rnr-docs.vercel.app/getting-started/common-patterns/#programmatically-showing-and-hiding-components

@habaieba
Copy link

habaieba commented Mar 26, 2025

Hi, I can't show my dropdown menu on headerRight even with onPressIn. Button is pressed as I see my test log, and the button response seems to tell that dropdown is actually showing somewhere (react dev tools shows menu components). Maybe it's showing outside screen...
Do you have a clue ?

import { Stack, useLocalSearchParams } from "expo-router";
import HeaderMenu from "~/components/HeaderMenu";

import WorkDetailsScreen from "~/screens/WorkDetailsScreen";

export default function Screen() {
  const { id: estimateId, workId } = useLocalSearchParams<{
    id: string;
    workId: string;
  }>();

  return (
    <>
      <Stack.Screen
        options={{
          title: "Édition de la rubrique",
          headerRight: () => <HeaderMenu />,
        }}
      />
      <WorkDetailsScreen estimateId={estimateId} workId={workId} />
    </>
  );
}

HeaderMenu

import { useSafeAreaInsets } from "react-native-safe-area-context";
import { Button } from "~/components/ui/button";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuSeparator,
  DropdownMenuTrigger,
} from "~/components/ui/dropdown-menu";
import { Text } from "~/components/ui/text";
import { CircleEllipsis } from "~/lib/icons/CircleEllipsis";

export default function HeaderMenu() {
  const insets = useSafeAreaInsets();
  const contentInsets = {
    top: insets.top,
    bottom: insets.bottom,
    left: 12,
    right: 12,
  };
  return (
    <DropdownMenu>
      <DropdownMenuTrigger asChild>
        <Button
          size={"icon"}
          variant={"ghost"}
          onPress={() => console.log("test")}
        >
          <CircleEllipsis className="text-foreground" />
        </Button>
      </DropdownMenuTrigger>
      <DropdownMenuContent insets={contentInsets} className="w-64 native:w-72">
        <DropdownMenuLabel>My Account</DropdownMenuLabel>
        <DropdownMenuSeparator />
        <DropdownMenuSeparator />
        <DropdownMenuItem>
          <Text>GitHub</Text>
        </DropdownMenuItem>
        <DropdownMenuItem>
          <Text>Support</Text>
        </DropdownMenuItem>
        <DropdownMenuItem disabled>
          <Text>API</Text>
        </DropdownMenuItem>
        <DropdownMenuSeparator />
      </DropdownMenuContent>
    </DropdownMenu>
  );
}

@kevin-griley
Copy link

kevin-griley commented Mar 28, 2025

It is working it just offscreen by the screen height. It does seem like a bug, I fixed it by manually setting the position of the ContentMenu for native.

<DropdownMenuContent
    insets={contentInsets}
    className="w-64 native:w-72"
    style={{
        position:
            Platform.OS !== 'web' ? 'absolute' : undefined,
        top:
            Platform.OS !== 'web' ? insets.top + 35 : undefined,
    }}
>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants