React -Headless Popover 2.1V - close issue after router push #3533
Replies: 3 comments
-
I can work on this issue. Please assign it to me. |
Beta Was this translation helpful? Give feedback.
-
Updated it |
Beta Was this translation helpful? Give feedback.
-
Hey! The codesnippet has a lot of missing parts and it's hard to replicate the problem with just that. Can you generate a minimal GitHub repo or CodeSandbox where the issue is clear? You don't need the You also can't use the While waiting for a reproduction, a few things you can try are:
Locally, when I add some of the missing pieces, the import {
CloseButton,
Popover,
PopoverBackdrop,
PopoverButton,
PopoverGroup,
PopoverPanel,
Transition,
} from '@headlessui/react'
import { useState } from 'react'
export default function Header() {
const showInput = true
const [searchValue, setSearchValue] = useState('')
const handleSearch = () => {
console.log('Handling search')
}
return (
<>
<PopoverGroup className="ml-8">
<div className="flex h-full justify-center space-x-8">
<Popover className="flex">
<div className="relative flex ">
{/* custom-overlay on top */}
<PopoverButton
className={`rounded p-2.5 focus:outline-none ${
showInput ? 'active bg-black' : 'bg-white'
}`}
>
search
</PopoverButton>
</div>
<Transition
enter="transition ease-in-out duration-300 transform"
enterFrom="-translate-y-full opacity-0"
enterTo="translate-y-0 opacity-100"
leave="transition ease-in-out duration-300 transform"
leaveFrom="translate-y-0 opacity-100"
leaveTo="-translate-y-full opacity-100"
>
<PopoverPanel className="custom-popover absolute inset-x-0 top-full -z-10">
<PopoverBackdrop className="overlay-bg fixed inset-0 -z-50 h-screen " />
<div className="popup-background">
<div className="bg-white">
<div className=" mm_col container relative mx-auto flex justify-between gap-4 bg-white px-8 py-5 lg:px-0">
<input
type="text"
placeholder="What are you looking for...?"
value={searchValue}
onChange={(event) => setSearchValue(event.target.value)}
onKeyDown={(event) => {
if (event.key == 'Enter') {
handleSearch()
}
}}
className="filter-btn custom_input"
/>
{searchValue && (
<button
className="absolute right-28 top-7 text-gray-500"
onClick={() => setSearchValue('')}
>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M18 6L6 18M6 6L18 18"
stroke="black"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
</button>
)}
<CloseButton
className={`${
searchValue ? ' ' : 'opacity-20'
} rounded border border-gray-400 bg-white px-4 py-2 font-semibold text-gray-800 shadow`}
onClick={handleSearch}
disabled={!searchValue}
>
Search
</CloseButton>
</div>
</div>
</div>
</PopoverPanel>
</Transition>
</Popover>
</div>
</PopoverGroup>
</>
)
} Now that said, this only works when you click on the button or press enter while the button is focused. If you press Enter in the search field it will not To solve this, make sure to wrap them in a Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Edit from @RobinMalfait: added codeblocks for syntax highlighting
HI,
Using Headless popover 2.1V.
We have closing issue after input search clicking enter and redirecting through router.push(). Headless popover state was open after redirect to the page, we tried usestate, ref nothing helped. In DOM element still shows and state not updated.
But using buttonClose click it was working fine. we want onclick event to update the state = 'close'
Sample:
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions