首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未使用工具提示组件的Component

未使用工具提示组件的Component
EN

Stack Overflow用户
提问于 2021-12-23 22:30:40
回答 1查看 647关注 0票数 0

我试图在工具提示组件中使用反应门。没有错误,但它似乎不起作用:

  1. 工具提示仍然被带有overflow:hidden的父容器部分隐藏。
  2. 我没有看到它添加到#root之外的新div中。
代码语言:javascript
复制
import { Portal } from 'react-portal';

return (
    <>
      <Wrapper
        onMouseEnter={showTip}
        onMouseLeave={hideTip}
        ref={triggerRef}
      >
        {children}
      </Wrapper>

      {render && (
        <Portal node={triggerRef.current}>
          <Content
            placement={placement}
            fade={active}
          >
            {content}
          </Content>
        </Portal>
      )}
    </>
  );

这是完整代码的码箱

EN

回答 1

Stack Overflow用户

发布于 2021-12-23 23:45:12

我认为没有什么问题,问题在于您的风格,我对您的portal.js文件做了一些修改:

代码语言:javascript
复制
  if (typeof window === "object") {
    if (target) {
      root = document.getElementById("root");
    }
    el = document.createElement("div");
    el.setAttribute('style', 'position:relative'); // this line
    el.id = "portal-root";
  } 

因为您的工具提示显示在文本上,onMouseLeave立即被调用,工具提示再次隐藏,因此在样式组件中和在顶部情况下,当我更改底部样式时:

代码语言:javascript
复制
  ${({ placement }) =>
    placement === "top" &&
    css`
      bottom: calc(100% + 50px); // this line
      &::before {
        top: calc(100% - 10px);
      }
    `}

及其工作:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70467997

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档