|
1 | 1 | import React, { HTMLAttributes } from 'react'; |
2 | 2 | import ReactDOM from 'react-dom'; |
| 3 | +import raf from 'rc-util/lib/raf'; |
3 | 4 | import contains from 'rc-util/lib/Dom/contains'; |
4 | 5 | import findDOMNode from 'rc-util/lib/Dom/findDOMNode'; |
5 | 6 | import { composeRef, supportRef } from 'rc-util/lib/ref'; |
@@ -538,19 +539,31 @@ export function generateTrigger( |
538 | 539 | ); |
539 | 540 | }; |
540 | 541 |
|
541 | | - getContainer = () => { |
| 542 | + attachParent = (popupContainer: HTMLDivElement) => { |
542 | 543 | const { props } = this; |
| 544 | + const mountNode = props.getPopupContainer |
| 545 | + ? props.getPopupContainer(this.getRootDomNode()) |
| 546 | + : props.getDocument().body; |
| 547 | + |
| 548 | + if (mountNode) { |
| 549 | + mountNode.appendChild(popupContainer); |
| 550 | + } else { |
| 551 | + // Retry after frame render in case parent not ready |
| 552 | + raf(() => { |
| 553 | + this.attachParent(popupContainer); |
| 554 | + }); |
| 555 | + } |
| 556 | + }; |
| 557 | + |
| 558 | + getContainer = () => { |
543 | 559 | const popupContainer = document.createElement('div'); |
544 | 560 | // Make sure default popup container will never cause scrollbar appearing |
545 | 561 | // https://github.com/react-component/trigger/issues/41 |
546 | 562 | popupContainer.style.position = 'absolute'; |
547 | 563 | popupContainer.style.top = '0'; |
548 | 564 | popupContainer.style.left = '0'; |
549 | 565 | popupContainer.style.width = '100%'; |
550 | | - const mountNode = props.getPopupContainer |
551 | | - ? props.getPopupContainer(this.getRootDomNode()) |
552 | | - : props.getDocument().body; |
553 | | - mountNode.appendChild(popupContainer); |
| 566 | + this.attachParent(popupContainer); |
554 | 567 | return popupContainer; |
555 | 568 | }; |
556 | 569 |
|
|
0 commit comments