Place MaterialUI Tooltip “on top” of anchor element? (React)

核能气质少年 提交于 2020-05-16 02:59:32

问题


Seems impossible to place <Tooltip> "on top" (stacked/layered above) the triggering anchor element.

It always appears outside the parent, using "placement" to decide where. I believe it's the Flip tool within Popper that manages placement and ensures visibility. I've tried passing Popper option modifiers to disable flip, and adjusting the offset. Some recommendations were to skip preventing overflow, and disable GPU acceleration. I'm down a rabbit-hole of MaterialUI internals to accomplish this. I commented out what seems like unlikely overkill solutions.

Example outside MUI: react-tooltip (includes pointer tracking, beyond this question).

<Tooltip title="My Label" placement="top" PopperProps={{
  popperOptions: {
    modifiers: {
      flip: { enabled: false },
      // computeStyle: {
      //   gpuAcceleration: false
      // },
      // preventOverflow: {
      //   enabled: false,
      //   padding: 0
      // },
      offset: {
        offset: '-20px -20px'
      }
    }
  }
}}></Tooltip>
    <h3>My Text</h3>
</Tooltip>

回答1:


You need to enable the offset like this:

<Tooltip title="My Label" placement="top" PopperProps={{
  popperOptions: {
    modifiers: {
      flip: { enabled: false },
      offset: {
        enabled: true,
        offset: '0px -60px'
      }
    }
  }
}}>
    <h3>My Text</h3>
</Tooltip>

this will enable you to place the tooltip on top



来源:https://stackoverflow.com/questions/61112311/place-materialui-tooltip-on-top-of-anchor-element-react

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!