最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Material UI ToolTip is not shown correctly inside a container with overflow scroll - Stack Overflow

programmeradmin2浏览0评论

In my reactJS application, I use a list of Material UI ToolTip with IconButton as children inside a div container with overflow: scroll. In a particualar row the Material UI ToolTip looks like this:

   <ClickAwayListener onClickAway={handleTooltipClose}>
      <Tooltip
        PopperProps={{
          disablePortal: true,
        }}
        onClose={handleTooltipClose}
        open={open}
        disableFocusListener
        disableHoverListener
        disableTouchListener
        title={data}
        arrow
      >
        <InfoOutlinedIcon
          className={classes.root}
          onClick={handleTooltipOpen}
        />
      </Tooltip>
    </ClickAwayListener>

The position of the tooltip is also not correct as well as the display:

I cannot use overflow: visible; on the div container containing the table and ToolTip as I want the scroll behavior, is there any way I can make the ToolTip pop out of the container without clipping?

In my reactJS application, I use a list of Material UI ToolTip with IconButton as children inside a div container with overflow: scroll. In a particualar row the Material UI ToolTip looks like this:

   <ClickAwayListener onClickAway={handleTooltipClose}>
      <Tooltip
        PopperProps={{
          disablePortal: true,
        }}
        onClose={handleTooltipClose}
        open={open}
        disableFocusListener
        disableHoverListener
        disableTouchListener
        title={data}
        arrow
      >
        <InfoOutlinedIcon
          className={classes.root}
          onClick={handleTooltipOpen}
        />
      </Tooltip>
    </ClickAwayListener>

The position of the tooltip is also not correct as well as the display:

I cannot use overflow: visible; on the div container containing the table and ToolTip as I want the scroll behavior, is there any way I can make the ToolTip pop out of the container without clipping?

Share Improve this question edited Oct 6, 2020 at 9:15 Negin msr 1139 bronze badges asked Oct 6, 2020 at 5:51 theSereneRebeltheSereneRebel 3061 gold badge4 silver badges16 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 10

Material-UI uses Popper.js. You can make use of different Popper.js Options via Tooltip PopperProps to handle these types of situations. In your scenario, I think you can make use of preventOverflow modifier

<Tooltip
  PopperProps={{
    disablePortal: true,
    popperOptions: {
      positionFixed: true,
      modifiers: {
        preventOverflow: {
          enabled: true,
          boundariesElement: "window" // where "window" is the boundary
        }
      }
    }
  }}
  title={popperTitle}
  aria-label="add"
>

In my case, I fixed almost the same problem with disabling flip moddifier for Popper:

<Tooltip
        title={title}
        placement="top"
        arrow
        open={open}
        PopperProps={{
            disablePortal: true,
            popperOptions: {
                modifiers: [
                    {
                        name: 'flip',
                        enabled: false
                    }
                ]
            }
        }}
    >
        {children}
    </Tooltip>

The answer from @95faf8e76605e973 did not work 100% for me. I had to specify the modifier 'preventOverflow' as follows (see below). Otherwise it worked perfectly.

<Tooltip
PopperProps={{
  disablePortal: true,
  popperOptions: {
    positionFixed: true,
    modifiers: {
      name: 'preventOverflow',
      options: {
        enabled: true,
        boundariesElement: "window" // where "window" is the boundary
      }
    }
  }
}}
title={popperTitle}
aria-label="add"
>
发布评论

评论列表(0)

  1. 暂无评论