Popover does not work on Nextjs 13
What package within Headless UI are you using?
@headlessui/react
What version of that package are you using?
"@headlessui/react": "^0.0.0-insiders.6f205f0"
Nextjs:13
What browser are you using?
Chrome
Reproduction URL
https://aitdoors-front-3u46nl0cn-seodapop.vercel.app/
A public GitHub repo that includes a minimal reproduction of the bug. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn't matter if your real project is private/confidential, since we want a link to a separate, isolated reproduction anyways. Unfortunately we can't provide support without a reproduction, and your issue will be closed with no comment if this is not provided.
`import { Fragment } from 'react' import { Popover, Transition } from '@headlessui/react' import Link from 'next/link' import Image from 'next/image' import { Bars3Icon, BookmarkSquareIcon, BriefcaseIcon, BuildingOfficeIcon, ChevronDownIcon, ComputerDesktopIcon, GlobeAltIcon, InformationCircleIcon, NewspaperIcon, ShieldCheckIcon, UserGroupIcon, XMarkIcon, } from '@heroicons/react/24/outline'
const company = [ { name: 'About', href: '#', icon: InformationCircleIcon }, { name: 'Customers', href: '#', icon: BuildingOfficeIcon }, { name: 'Press', href: '#', icon: NewspaperIcon }, { name: 'Careers', href: '#', icon: BriefcaseIcon }, { name: 'Privacy', href: '#', icon: ShieldCheckIcon }, ] const resources = [ { name: 'Community', href: '#', icon: UserGroupIcon }, { name: 'Partners', href: '#', icon: GlobeAltIcon }, { name: 'Guides', href: '#', icon: BookmarkSquareIcon }, { name: 'Webinars', href: '#', icon: ComputerDesktopIcon }, ] const blogPosts = [ { id: 1, name: 'Boost your conversion rate', href: '#', preview: 'Eget ullamcorper ac ut vulputate fames nec mattis pellentesque elementum. Viverra tempor id mus.', imageUrl: 'https://images.unsplash.com/photo-1558478551-1a378f63328e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2849&q=80', }, { id: 2, name: 'How to use search engine optimization to drive traffic to your site', href: '#', preview: 'Eget ullamcorper ac ut vulputate fames nec mattis pellentesque elementum. Viverra tempor id mus.', imageUrl: 'https://images.unsplash.com/photo-1486312338219-ce68d2c6f44d?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=2300&q=80', }, ]
function classNames(...classes: any[]) {
return classes.filter(Boolean).join(' ')
}
export const TopMenu = () => {
return (
<>
)
}` Describe your issue Describe the problem you're seeing, any important steps to reproduce, and what behavior you expect instead. popover does not work on Nextjs 13. I already disabled nextjs strict mode but I still do not have any luck getting it to work. I am importing the menu in my _document file. In mobile view we have a sandwich menu with a code above but the popover does not open/close
Hey! As noted in the issue template, we can't help out without a minimal reproduction of this issue as a GitHub repo. A public GitHub repo that includes a minimal reproduction of the bug. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn't matter if your real project is private/confidential, since we want a link to a separate, isolated reproduction anyways. Unfortunately we can't provide support without a reproduction, and your issue will be closed with no comment if this is not provided. I am going to close this issue, but if you're able to provide a minimal reproduction of this issue as a GitHub repo, I'd be happy to have another look 👍 <div className="hidden space-x-10 md:flex items-center">
<Link href="/about" className="text-base font-medium text-top-nav hover:text-white">
About us
</Link>
<Link href="/dealers" className="text-base font-medium text-top-nav hover:text-white">
Dealers
</Link>
<Link href="/portfolio" className="text-base font-medium text-top-nav hover:text-white">
Portfolio
</Link>
<button className='inline-flex rounded-full border-2 border-[#F4F6FC33] px-8 py-3 text-xs font-medium text-white shadow-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2'>
<Link href="/contact" className="text-base font-medium text-top-nav hover:text-white">
Contact us
</Link>
</button>
</div>
{/* <Transition
as={Fragment}
enter="duration-200 ease-out"
enterFrom="opacity-0 scale-95"
enterTo="opacity-100 scale-100"
leave="duration-100 ease-in"
leaveFrom="opacity-100 scale-100"
leaveTo="opacity-0 scale-95"
appear={true}
> */}
<Popover.Panel focus className="absolute transform p-2 transition md:hidden">
<div className="divide-y-2 divide-gray-50 rounded-lg bg-white shadow-lg ring-1 ring-black ring-opacity-5">
<div className="px-5 pt-5 pb-6">
<div className="flex items-center justify-between">
<div>
<Image
className="h-8 w-auto"
src="/images/logo.jpg"
alt="Company Logo"
width={42}
height={42}
/>
</div>
<div className="-mr-2">
<Popover.Button className="inline-flex items-center justify-center rounded-md bg-white p-2 text-gray-400 hover:bg-gray-100 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-indigo-500">
<span className="sr-only">Close menu</span>
<XMarkIcon className="h-6 w-6" aria-hidden="true" />
</Popover.Button>
</div>
</div>
</div>
<div className="space-y-6 py-6 px-5">
<div className="grid grid-cols-2 gap-y-4 gap-x-8">
<Link href="/about" className="text-base font-medium text-top-nav hover:text-white">
About Us
</Link>
<a href="/about" className="text-base font-medium text-top-nav hover:text-white">
About Us
</a>
<Link href="/dealers" className="text-base font-medium text-top-nav hover:text-white">
Dealers
</Link>
<Link href="/Portfolio" className="text-base font-medium text-top-nav hover:text-white">
Portfolio
</Link>
<Link href="/contact" className="text-base font-medium text-top-nav hover:text-white">
Contact us
</Link>
</div>
</div>
</div>
</Popover.Panel>
{/* </Transition> */}
</div>
</div>
</Popover >
<Popover className="relative z-0">
{({ open }) => (
<>
<div className="relative z-10 bg-white shadow">
<div className="mx-auto flex max-w-7xl p-6 lg:px-8">
<Popover.Button
data-headlessui-state="open"
className={classNames(
open ? 'text-gray-900' : 'text-gray-500',
'group inline-flex items-center rounded-md bg-white text-base font-medium hover:text-gray-900 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2'
)}
>
<span>Solutions</span>
<ChevronDownIcon
className={classNames(
open ? 'text-gray-600' : 'text-gray-400',
'ml-2 h-5 w-5 group-hover:text-gray-500'
)}
aria-hidden="true"
/>
</Popover.Button>
</div>
</div>
<Transition
as={Fragment}
enter="transition ease-out duration-200"
enterFrom="opacity-0 -translate-y-1"
enterTo="opacity-100 translate-y-0"
leave="transition ease-in duration-150"
leaveFrom="opacity-100 translate-y-0"
leaveTo="opacity-0 -translate-y-1"
>
<Popover.Panel className="absolute inset-x-0 z-10 transform shadow-lg">
<div className="absolute inset-0 flex" aria-hidden="true">
<div className="w-1/2 bg-white" />
<div className="w-1/2 bg-gray-50" />
</div>
<div className="relative mx-auto grid max-w-7xl grid-cols-1 lg:grid-cols-2">
<nav
className="grid gap-y-10 bg-white py-8 px-6 sm:grid-cols-2 sm:gap-x-8 sm:py-12 lg:px-8 xl:pr-12"
aria-labelledby="solutions-heading"
>
<h2 id="solutions-heading" className="sr-only">
Solutions menu
</h2>
<div>
<h3 className="text-base font-medium text-gray-500">Company</h3>
<ul role="list" className="mt-5 space-y-6">
{company.map((item) => (
<li key={item.name} className="flow-root">
<a
href={item.href}
className="-m-3 flex items-center rounded-md p-3 text-base font-medium text-gray-900 transition duration-150 ease-in-out hover:bg-gray-50"
>
<item.icon className="h-6 w-6 flex-shrink-0 text-gray-400" aria-hidden="true" />
<span className="ml-4">{item.name}</span>
</a>
</li>
))}
</ul>
</div>
<div>
<h3 className="text-base font-medium text-gray-500">Resources</h3>
<ul role="list" className="mt-5 space-y-6">
{resources.map((item) => (
<li key={item.name} className="flow-root">
<a
href={item.href}
className="-m-3 flex items-center rounded-md p-3 text-base font-medium text-gray-900 transition duration-150 ease-in-out hover:bg-gray-50"
>
<item.icon className="h-6 w-6 flex-shrink-0 text-gray-400" aria-hidden="true" />
<span className="ml-4">{item.name}</span>
</a>
</li>
))}
</ul>
</div>
</nav>
<div className="bg-gray-50 py-8 px-6 sm:py-12 lg:px-8 xl:pl-12">
<div>
<h3 className="text-base font-medium text-gray-500">From the blog</h3>
<ul role="list" className="mt-6 space-y-6">
{blogPosts.map((post) => (
<li key={post.id} className="flow-root">
<a
href={post.href}
className="-m-3 flex rounded-lg p-3 transition duration-150 ease-in-out hover:bg-gray-100"
>
<div className="hidden flex-shrink-0 sm:block">
<img className="h-20 w-32 rounded-md object-cover" src={post.imageUrl} alt="" />
</div>
<div className="min-w-0 flex-1 sm:ml-8">
<h4 className="truncate text-base font-medium text-gray-900">{post.name}</h4>
<p className="mt-1 text-sm text-gray-500">{post.preview}</p>
</div>
</a>
</li>
))}
</ul>
</div>
<div className="mt-6 text-sm font-medium">
<a href="#" className="text-indigo-600 transition duration-150 ease-in-out hover:text-indigo-500">
View all posts
<span aria-hidden="true"> →</span>
</a>
</div>
</div>
</div>
</Popover.Panel>
</Transition>
</>
)}
</Popover>
</>