diff --git a/packages/clerk-js/src/ui/components/OrganizationSwitcher/OrganizationSwitcher.tsx b/packages/clerk-js/src/ui/components/OrganizationSwitcher/OrganizationSwitcher.tsx index b066480dec2..b7e7dffa138 100644 --- a/packages/clerk-js/src/ui/components/OrganizationSwitcher/OrganizationSwitcher.tsx +++ b/packages/clerk-js/src/ui/components/OrganizationSwitcher/OrganizationSwitcher.tsx @@ -1,6 +1,6 @@ import { useId } from 'react'; -import { AcceptedInvitationsProvider, withCoreUserGuard } from '../../contexts'; +import { AcceptedInvitationsProvider, useOrganizationSwitcherContext, withCoreUserGuard } from '../../contexts'; import { Flow } from '../../customizables'; import { Popover, withCardStateProvider, withFloatingTree } from '../../elements'; import { usePopover } from '../../hooks'; @@ -8,7 +8,9 @@ import { OrganizationSwitcherPopover } from './OrganizationSwitcherPopover'; import { OrganizationSwitcherTrigger } from './OrganizationSwitcherTrigger'; const _OrganizationSwitcher = withFloatingTree(() => { + const { defaultOpen, portal } = useOrganizationSwitcherContext(); const { floating, reference, styles, toggle, isOpen, nodeId, context } = usePopover({ + defaultOpen, placement: 'bottom-start', offset: 8, }); @@ -32,6 +34,7 @@ const _OrganizationSwitcher = withFloatingTree(() => { nodeId={nodeId} context={context} isOpen={isOpen} + portal={portal} > { - const { defaultOpen } = useUserButtonContext(); + const { defaultOpen, portal } = useUserButtonContext(); const { floating, reference, styles, toggle, isOpen, nodeId, context } = usePopover({ defaultOpen, placement: 'bottom-end', @@ -33,6 +33,7 @@ const _UserButton = withFloatingTree(() => { nodeId={nodeId} context={context} isOpen={isOpen} + portal={portal} > or in await Clerk.load() @@ -949,6 +954,11 @@ export type OrganizationSwitcherProps = CreateOrganizationMode & * Controls the default state of the OrganizationSwitcher */ defaultOpen?: boolean; + /** + * By default, the popover will be rendered outside of the app root and into the body. + * @default true + */ + portal?: boolean; /** * By default, users can switch between organization and their personal account. * This option controls whether OrganizationSwitcher will include the user's personal account