From 0c3dd9259216d2242c9debe4f95750f63f30ab2d Mon Sep 17 00:00:00 2001 From: Netfan Date: Tue, 25 Feb 2025 22:07:56 +0800 Subject: [PATCH] fix: getPopupContainer will return closet form first (#5612) --- packages/utils/src/helpers/get-popup-container.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/utils/src/helpers/get-popup-container.ts b/packages/utils/src/helpers/get-popup-container.ts index ca5a72dd..6aa84d6d 100644 --- a/packages/utils/src/helpers/get-popup-container.ts +++ b/packages/utils/src/helpers/get-popup-container.ts @@ -1,6 +1,10 @@ /** - * Returns the parent node of the given element or the document body if the element is not provided.it + * If the node is holding inside a form, return the form element, + * otherwise return the parent node of the given element or + * the document body if the element is not provided. */ export function getPopupContainer(node?: HTMLElement): HTMLElement { - return (node?.parentNode as HTMLElement) ?? document.body; + return ( + node?.closest('form') ?? (node?.parentNode as HTMLElement) ?? document.body + ); }