Skip to content

[EuiTooltip] Add logic to close all tooltips before showing another EuiTooltip instance #6423

Closed

Description

@1Copenut

Description

@jughosta reached out to the EUI team for a way to prevent tooltips persisting on the screen after click events. This issue is being tracked in Kibana #144482.

The EUI team proposed a UX solution where we prevent two tooltips being present in the DOM. If a user toggles a tooltip, we should check for any tooltips present, close them, then reveal the new tooltip.

@constancecchen has proposed an enhancement using React.Context:

A new context/provider within EuiProvider just for tooltips, similar to how we have CurrentEuiBreakpointProvider now.

<CurrentEuiBreakpointProvider>{children}</CurrentEuiBreakpointProvider>

Activity

  1. chandlerprall commented on Nov 29, 2022

    @chandlerprall
    Contributor

    I'd recommend a singleton to track & enforce the one active tooltip rule, instead of needing context to be set & communicating through that. Essentially, the same service/logic that would come from context becomes a JS import (or lives in tool_tip.tsx directly),

    import { registerTooltip, deregisterTooltip } from 'tooltip_logic';
    
    ...
    
    showTooltip = () => {
      ... existing logic ...
      registerTooltip(this.hideToolTip); // tell the service a new tooltip is active, provides a callback function for the service to close the tooltip if another one becomes active; if there is already an active tooltip, this call to registerTooltip will dismiss it
    }
    
    hideToolTip = () => {
      ... existing logic ...
      deregisterTooltip(this.hideToolTip);
    }
    
  2. cee-chen commented on Nov 29, 2022

    @cee-chen
    Contributor

    Interesting - I'm not entirely sure I see how a singleton would function correctly with the state updates needed to determine individual tooltip visibility. Do you have a POC or codesandbox to demonstrate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions