diff --git a/.changeset/thin-points-sip.md b/.changeset/thin-points-sip.md new file mode 100644 index 0000000000..8313095ced --- /dev/null +++ b/.changeset/thin-points-sip.md @@ -0,0 +1,5 @@ +--- +"@heroui/popover": patch +--- + +fix(popover): arrow glitch in popover content (#4142) diff --git a/packages/components/popover/__tests__/popover.test.tsx b/packages/components/popover/__tests__/popover.test.tsx index 2b2d36e940..cd8d173c30 100644 --- a/packages/components/popover/__tests__/popover.test.tsx +++ b/packages/components/popover/__tests__/popover.test.tsx @@ -369,3 +369,40 @@ it("should close popover on scroll when shouldCloseOnScroll is false", async () // assert that the popover is still open expect(popover).toHaveAttribute("aria-expanded", "true"); }); + +it("should display popover content only after content is ready", async () => { + jest.useFakeTimers(); + + const TestComponent = () => { + const [content, setContent] = React.useState(""); + + React.useEffect(() => { + const timer = setTimeout(() => { + setContent("test content"); + }, 1000); + + return () => clearTimeout(timer); + }, []); + + return ( + + + + + {content} + + ); + }; + + const wrapper = render(); + + expect(wrapper.queryByTestId("content-test")).not.toBeInTheDocument(); + + act(() => { + jest.advanceTimersByTime(1000); + }); + + expect(wrapper.getByTestId("content-test")).toBeInTheDocument(); + + jest.useRealTimers(); +}); diff --git a/packages/components/popover/src/popover-content.tsx b/packages/components/popover/src/popover-content.tsx index d0d16420cf..473aa360d8 100644 --- a/packages/components/popover/src/popover-content.tsx +++ b/packages/components/popover/src/popover-content.tsx @@ -15,7 +15,7 @@ import {usePopoverContext} from "./popover-context"; export interface PopoverContentProps extends AriaDialogProps, Omit { - children: ReactNode | ((titleProps: DOMAttributes) => ReactNode); + children?: ReactNode | ((titleProps: DOMAttributes) => ReactNode); } const domAnimation = () => import("@heroui/dom-animation").then((res) => res.default); @@ -47,14 +47,16 @@ const PopoverContent = (props: PopoverContentProps) => { const Component = as || OverlayComponent || "div"; - const content = ( + const content = children && ( <> {!isNonModal && } - -
- {typeof children === "function" ? children(titleProps) : children} -
-
+ { + +
+ {typeof children === "function" ? children(titleProps) : children} +
+
+ } );