oruga icon indicating copy to clipboard operation
oruga copied to clipboard

Some findings on tooltip

Open cyberfly opened this issue 4 years ago • 11 comments

Hi just want to report some issues that I found when using o-tooltip

  1. The tooltip positioning is not reacted to the edge

For example, the placement is top. Usually Bootstrap tooltip will auto adjust itself to Bottom to avoid the edge

image


  1. There is no variable to customize tooltip arrow color. For example the sceenshot show the tooltip arrow is using default border color in my project

image

So if I customize the tooltip background color inside app.scss

$tooltip-background-color: rgba(0, 0, 0, 0.75);
@import "@oruga-ui/oruga/src/scss/oruga-full.scss";

It will looks like this. Notice that the arrow color doesnt change

image

Thanks for the hardwork!

cyberfly avatar Mar 17 '21 07:03 cyberfly

@cyberfly there isn't auto position feature at the moment but in your case you might use append-to-body prop.

The SCSS variable is correct, please check if something override it in your CSS (color attribute in o-tip__arrow)

jtommy avatar Mar 17 '21 09:03 jtommy

@cyberfly I had the same issue with the arrow color using oruga with tailwindcss.

Looks like the arrow color is affected by the border-top-color property which is in fact modified by tailwind.

Screenshot_20211125_143338

To fix it, I had to set it manually on my overrides:

.o-tip__arrow {
  border-top-color: currentColor;
}

dami2 avatar Nov 25 '21 19:11 dami2

@dami2 I don't understand, can you reproduce it on codepen/codesandbox?

jtommy avatar Nov 26 '21 17:11 jtommy

@dami2 I don't understand, can you reproduce it on codepen/codesandbox?

Here is the code sandbox: https://codesandbox.io/s/orugaui-tooltip-t9020

Some clarifications to be fair, I'm not sure if this is the case @cyberfly was reporting:

  • I'm using oruga module in nuxt
  • I'm using tailiwind in nuxt with the comunity module (https://github.com/nuxt-community/tailwindcss-module)
  • The override of border-top-color only affects the tooltip on position = top (default)

that said, hope it can help

dami2 avatar Dec 12 '21 19:12 dami2

Check https://github.com/oruga-ui/oruga/blob/5e02268c7f9c3972a857063f14f28bb0cfbad762/packages/oruga/src/scss/components/_tooltip.scss#L20

As you can see the border depends on position and you should override or add a new class for each position

jtommy avatar Dec 12 '21 19:12 jtommy

I've also had the need for an auto position on Tooltips, however that can quickly get complex and I can see why it would be out of scope.

It might be a good idea to trigger an event on tooltips when they open (active). We could then add our own functionality to check if they're off-screen etc.

sambedingfield avatar Dec 27 '21 13:12 sambedingfield

It's an interesting feature, we'll schedule it surely

jtommy avatar Dec 27 '21 14:12 jtommy

I'm glad this is being considered! Whatever placement solution you come up with, can it also be applied to the directions of dropdown menus?

Screen Shot 2022-04-14 at 9 07 21 PM

amanpatel avatar Apr 15 '22 02:04 amanpatel

For a project I've been working on, I ended up implementing a little hack that basically finds the bounding rectangle of the tooltip content, translates it to all four possible positions, and picks the position that provides the greatest overlap with the viewport. If that's a viable strategy for Oruga's needs, I should be able to draft up a PR that integrates that strategy into Oruga itself.

API-wise, I'm imagining that the position prop could take an array of strings (top, bottom, left, or right), and the component would test each position, picking the "best" one, with ties broken in favor of earlier entries in the array.

blm768 avatar Jun 15 '22 21:06 blm768

@blm768 sure, you are welcome. Position prop could accept "auto" as value

jtommy avatar Jun 15 '22 21:06 jtommy

FWIW, there's https://github.com/Akryum/floating-vue which handles a lot of popup best practices (including focus/accessibility). Might be useful to incorporate that.

ishitatsuyuki avatar Jul 24 '22 08:07 ishitatsuyuki