get-popup-container.ts 354 B

12345678910
  1. /**
  2. * If the node is holding inside a form, return the form element,
  3. * otherwise return the parent node of the given element or
  4. * the document body if the element is not provided.
  5. */
  6. export function getPopupContainer(node?: HTMLElement): HTMLElement {
  7. return (
  8. node?.closest('form') ?? (node?.parentNode as HTMLElement) ?? document.body
  9. );
  10. }