Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Patch for getPopupContainer check #200

Merged
merged 4 commits into from Sep 25, 2020
Merged

fix: Patch for getPopupContainer check #200

merged 4 commits into from Sep 25, 2020

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Sep 25, 2020

getPopupContainer 的参数传入 domNode 产生了先有鸡还是先有蛋的问题。如果在渲染之后才触发 getPopupContainer,那么 useEffect 中就无法获取弹层内的节点:

const someRef = useRef();
useEffect(() => {
  console.log(someRef.current);
}, []);

return (
  <Trigger
    visible
    getPopupContainer={(node) => node.parentNode}
    popup={<div ref={someRef} />}
  >
    <button />
  </Trigger>
);

如果先行渲染 popup,那么此时 getPopupContainer 的 dom 则还没有 ready。

现在做了如下改造,如果发现 getPopupContainer 没有 triggerNode 参数,则同时触发。如果有则异步触发。因而缩小冲突范围,只有在即用了 triggerNode 又使用 popup[ref] 的场景下会变成延迟触发。

ref https://codesandbox.io/s/eloquent-mclean-ss93m?file=/src/App.js

@zombieJ zombieJ merged commit 7d22219 into master Sep 25, 2020
@delete-merged-branch delete-merged-branch bot deleted the legacy branch September 25, 2020 06:20
@geekrainy
Copy link

破坏性更改,导致原先使用

<Popover getPopupContainer={node => node.parentNode as HTMLElement}>
</Popover>

用法全部报错。

@geekrainy
Copy link

5.0.6 已修复,忽略

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants