diff --git a/components/eventbrite/eventbriteModalButton.tsx b/components/eventbrite/eventbriteModalButton.tsx index cc0ab24d81..9292326f00 100644 --- a/components/eventbrite/eventbriteModalButton.tsx +++ b/components/eventbrite/eventbriteModalButton.tsx @@ -58,6 +58,8 @@ export const EventbriteModalButton = ({ const reactId = useId().replace(/[^a-zA-Z0-9_-]/g, ""); const containerId = `eventbrite-checkout-${eventId}-${reactId}`; const [open, setOpen] = useState(false); + // Gate the Popup on first open so a closed CTA mounts no react-responsive-modal; once opened it stays mounted for the close animation. + const [hasOpened, setHasOpened] = useState(false); const [scriptLoaded, setScriptLoaded] = useState(false); const [scriptFailed, setScriptFailed] = useState(false); // The popup portals its content, so bind via the callback ref once the node mounts, not when `open` flips. @@ -120,49 +122,54 @@ export const EventbriteModalButton = ({ variant={variant} className={className} textTinaField={textTinaField} - onClick={() => setOpen(true)} + onClick={() => { + setHasOpened(true); + setOpen(true); + }} > {children} - {/* Always mounted (for the close animation); the library unmounts contents while closed, resetting the widget. */} - setOpen(false)} - modalStyle={{ - maxWidth: CHECKOUT_WIDTH_PX, - padding: 0, // padding reads as a white border around the checkout - borderRadius: "0.375rem", // rounded-md, matching the site cards - overflow: "hidden", - background: THEME_SETTINGS.background, - }} - > - {scriptFailed && !scriptLoaded ? ( -
-

The booking form could not be loaded.

- - Register on the Eventbrite event page instead - -
- ) : ( -
- )} - + {/* Mounted only after the first open; stays mounted thereafter so the close animation plays. The library unmounts contents while closed, resetting the widget. */} + {hasOpened && ( + setOpen(false)} + modalStyle={{ + maxWidth: CHECKOUT_WIDTH_PX, + padding: 0, // padding reads as a white border around the checkout + borderRadius: "0.375rem", // rounded-md, matching the site cards + overflow: "hidden", + background: THEME_SETTINGS.background, + }} + > + {scriptFailed && !scriptLoaded ? ( +
+

The booking form could not be loaded.

+ + Register on the Eventbrite event page instead + +
+ ) : ( +
+ )} + + )} ); };