Skip to content

[FEAT REQ] Dynamic callback for disabling tooltip #1210

@nareshpingale

Description

@nareshpingale

In my application, I work with large datasets displayed in a data grid, where each cell has a tooltip. This extensive use of tooltips results in significant scripting time whenever a user interacts with them. The addEventListener and removeEventListener functions run on every cell and tooltip across the app. Consequently, even simple actions like scrolling or hovering through different cells through the table cause a considerable amount of scripting activity, impacting performance.

Currently, I've implemented a workaround tailored to my use case. Tooltips are necessary only when the data within a cell is clipped and an ellipsis appears. However, this solution is limited and not ideal for broader scenarios as it helps only because it reduces the amount of tooltips instead of solving the core problem.

I propose adding a data-tooltip-dynamic-hide attribute that accepts a callback function.

This callback would:

  • Receive the anchor element and anything else that you think would be ideal exposing outside to the users from inside of Tooltip.tsx
  • User would add logic using this callback. In my case compares the scrollWidth and offsetWidth properties to determine if the content is clipped.
    data-tooltip-dynamic-hide={(anchorElement)=>anchorElement.scrollWidth <= anchorElement.offsetWidth}
  • Decide whether to add the element as an anchor for the tooltip based on the result inside Tooltip.tsx

This approach would allow for more flexible and efficient tooltip management, accommodating various use cases and improving overall performance.

Alternatives I have explored for far

  • I have explored using data-tooltip-hidden attribute. But access correct ref and in such cases inside .map become troublesome.
  • As temporary workaround I have added show delays as to act as some kind of throttle.
  • Considered a broader fix adding throttle over useEffect callback which adds and removes listeners.

Additional context
I will be happy to open a PR introducing this feature or discussing other solutions around this.

Tooltips added on most basic example of tanstack table.
https://codesandbox.io/p/sandbox/angry-night-32nr8q

image

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