question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEAT REQ] Expose place context for use with multiple anchors

See original GitHub issue

Is your feature request related to a problem? Please describe. I have customized the Tooltip arrow with a border and CSS mask which necessitates that the arrow is conditionally rotated based on the place that the arrow is rendered.

I tried adding a thin wrapper around the <TooltipProvider/> which stores + allows context consumers to set the place. Then in a component containing a customized TooltipWrapper, I attempt to set the place when it changes. This does not work, as many TooltipWrappers are mounted simultaneously with listeners for onMouseover which triggers the global tooltip instance to anchor onto the element within the hovered TooltipWrapper. So I then need to verbosely add state management to set the placement only of the currently hovered TooltipWrapper instance. This is essentially juggling alongside the internal state management of this library, which feels a bit hacky for my purposes.

Describe the solution you’d like I would like to be able to use the internal useTooltip(), publicly exported in the dist, with the addition of activePlace to the TooltipContextData. Then I would easily be able to apply conditional Tailwind styles to the global tooltip instance based on:

/**
 * Global tooltip component that is rendered once at the root of the app, with dynamic content rendered into it by
 * `TooltipWrapper` instances.
 */
export const TooltipGlobal = function () {

  const { activePlace } = useTooltip();

  const arrowTransform = useMemo(() => {
    switch (activePlace) {
      case 'top':
        return 'rotate-[225deg]';

      case 'bottom':
        return 'rotate-45';

      case 'left':
        return '-rotate-45';

      case 'right':
        return 'rotate-[135deg]';

      default:
        throw new Error(`unhandled "activePlace" value: ${activePlace}`);
    }
  }, [placement]);

  return (
    <Tooltip
      classNameArrow={classNames(

        // bunch of custom styling here ...

        arrowTransform,
      )}
    />
  );
};

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
gabrieljablonskicommented, Dec 20, 2022

Exposing useTooltip() is something we’re considering on eventually doing if the need ever arises, but for now we decided against it since it can be a bit confusing to use.

At first glance, and if I understand correctly, your use case seems to fall a bit out of the scope of the project. I can’t think of many other use cases in which exposing internal tooltip data (such as activePlace) is beneficial, so I’m unsure about that.

I have customized the Tooltip arrow with a border and CSS mask which necessitates that the arrow is conditionally rotated based on the place that the arrow is rendered.

Something that is easy to do would be to give the tooltip arrow element different css classes according to the place value. Would that be enough for what you’re trying to do? I’d appreciate if you could do some testing.

If useTooltip() turns out to be the only way to solve your problem (which I honestly doubt) we’ll see what we can do.

0reactions
danielbarioncommented, Dec 20, 2022

Hi guys,

instead of:

<Tooltip
    classNameArrow={/* bunch of custom styling here ... */}
    classNameArrowPlace={
      top: 'rotate-[225deg]',
      bottom: 'rotate-45',
      left: '-rotate-45',
      right: 'rotate-[135deg]',
    }
  />

why not:

// https://www.npmjs.com/package/classnames
import classNames from 'classnames'


...
const [place, setPlace] = useState('top')
...


<Tooltip
    classNameArrow={classNames(/* bunch of custom styling here ... */, {
       'rotate-[225deg]': place === 'top',
       'rotate-45': place === 'bottom',
       '-rotate-45': place === 'left',
       'rotate-[135deg]': place === 'right',
    )}
  />

Why not use classnames package to handle these conditional CSS classes?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optimize Code for Multiple Anchor Recommendations
Passing multiple product anchors to Commerce Cloud Einstein enables you to provide product recommendations based on customer-specific items.
Read more >
Add anchor positioning functionality to MDC Simple Menu
We will add two new methods to MDCSimpleMenu: setAnchorCorner, which lets the client specify which corner of the anchor the top left corner ......
Read more >
SHEAR TRANSFER IN EXPOSED COLUMN BASE PLATES
This report presents the results of an experimental study investigating shear transfer mechanisms of column base plate details. This investigation is the ...
Read more >
NetSuite Applications Suite - Table of Contents
Use Accounting Contexts in Account Saved Searches ... Vendor Searches for Multi-Subsidiary Vendors ... Password Requirements and Policies in NetSuite.
Read more >
Designing Better Hyperlinks: A Detailed Guide - UX Collective
Moreover, a well-composed link makes sense out of context and typically combines a topic (for example, security, brand, marketing) and format (questionnaire, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found