Skip to content

[BUG] Wide tooltips can overflow the window boundaries in version 5 #1139

@dylemma

Description

@dylemma

Bug description
When you have a tooltip with long content, it can overflow the window. Solutions to similar reported issues are apparently unavailable in v5. It's particularly apparent when using a left/right placement with dynamic content and/or dynamic layout.

Version of Package
v5.25.0

To Reproduce
See https://codesandbox.io/p/sandbox/react-tooltip-overflow-9srs73
or just do

<Tooltip
  id="my-tooltip"
  place="left"
  float
/>
<span
  data-tooltip-id="my-tooltip"
  data-tooltip-content="Here is a very long string of text that will surely cause issues if I try to render it all in one line"
>
  Hover me
</span>

with some CSS that puts the <span> near the center of the screen.

Expected behavior
One of the following:

  • "squish" the tooltip so that it fits at its specified place (allowing the tooltip content to line-wrap)
  • have the tooltip ignore its place directive, e.g. if I set place="left" and it doesn't fit on the left or right, have it go to top/bottom if one of those would fit it on screen
  • provide some way for me to affect the tooltip's positioning myself (existing props in v5 don't seem to give me enough power to accomplish either of the above two behaviors)

Screenshots
image

Additional context
#476 and #599 seem related, but all of the suggested solutions seem unavailable in v5:

  • Can't use overridePosition in v5, and the position prop doesn't accept functions
  • afterShow no longer provides access to the tooltip element (AFAICT), so it is no longer possible to set its styles during the callback
  • Setting a max-width on the tooltip does not work because the width depends on the position of the anchor element relative to the edges of the screen

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions