Unexpected change in behavior of tooltips with direction option
See original GitHub issueIn the newest Version of Leaflet 1.7.1 the Tooltips are not displayed correct, if a direction is set.
To reproduce: Go to: https://leafletjs.com/examples/quick-start/example.html And add this in the console:
var marker = L.marker([51.52,-0.092]).addTo(mymap)
marker.bindTooltip('TEST', {
direction: 'left'
}).openTooltip()
The Tooltip should completly displayed on the left side of the marker but it is starting on the right side and then goes to the left side.
I think it has something to do with: #7155
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Solved: Tool tip - Power Platform Community - Microsoft
Tooltips only work when the user hovers over the control. That behavior cannot be changed. As an alternative you can put an icon...
Read more >Tooltips: How to create and use the mighty UI pattern - Appcues
Exit(s). There are a surprising number of ways to close a tooltip. The simplest option is to let users "x" out or dismiss...
Read more >How to Create & Use Tooltips in 2023 (+Examples) - Whatfix
Learn how to create and use interactive tooltips, learn best practices, see examples of well-designed tooltips, and tools to create your ...
Read more >Tooltip - OutSystems 11 Documentation
You can use the Tooltip UI Pattern to dynamically display ... You can also change the look and feel of the Tooltip by...
Read more >Tooltip Guidelines - Nielsen Norman Group
Remember that tooltips disappear, so instructions or other directly actionable information, like field requirements, shouldn't be in a tooltip.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you want to get back to old behaviour just like me, use this :
L.Icon.Default.prototype.options.tooltipAnchor = [0, 0];
Yes, that’s subjective like everything is.
I think it should be the way it is now, because otherwise
tooltipAnchor
andoffset
are both working with invertedx
coordinates when using{direction: 'left'}
. That is very confusing, especially when working with custom asymmetric icons.That
{direction: 'left'}
changes the behavior of these two other features is undocumented. Also, if that were the wanted default behavior, it should also apply similar totop
/bottom
to be consistent.From a point of what setting is where at which element it also makes sense.
tooltipAnchor
is a setting of the Icon, not of the Tooltip. The Icon is saying: these are the (relative) coordinates of thetooltipAnchor
.direction
says in which direction it is opening this tooltip (relative to that anchor). It should not manipulate the coordinates of the anchor, because that’s whatoffset
is there for.Not necessarily. If you use a icon that has a
tooltipAnchor
at the left side of the icon, you don’t have to use an offset at all.For that use case I personally would like to have a default
tooltipDirection
setting for the Icon itself that can be overwritten by the Tooltip.But yes, if you do have a icon that has a
tooltipAnchor
at the right, then you have to provide anoffset
to move the anchor to the left when you want to use{ direction: 'left' }
. The same is the case for{ direction: 'top' }
and{ direction: 'bottom' }
, you have to provide anoffset
if you want the anchor at another position. Why should{ direction: 'left' }
be different / special?The Icon is centered to the
iconAnchor
. We already have the two offsets for tooltips that are relative to theiconAnchor
:tooltipAnchor
at the icon leveloffset
at the tooltip level.We also have the other icon offset
popupAnchor
, and this is wheredirection
struck me. Because I was definingpopupAnchor
andtooltipAnchor
to be at the same point for a few dozens different asymmetrical icons. But thedirection
was changing thetooltipAnchor
, so that the Popups and Tooltips weren’t opening at the same point anymore.Having
{ direction: 'left' }
inverting the axis would be a convenient way for your use case, but that IMHO should not be part ofleft
itself but a separate setting (e.g.{ direction: 'invertedLeft'}
or{ direction: 'left', invertHorizontalAxis: true }
as mentioned in my last comment), because it’s inconsistent with the other directions and complicates the usages oftooltipAnchor
andoffset
.If, against my preference, the default of
left
should be inverting, then the documentation needs to be changed, and we’d need a way to disable this behavior (e.g.{direction: 'left'}
implies{ invertHorizontalAxis: true }
and can manually be disabled by setting{ direction: 'left', invertHorizontalAxis: false }
together):1.) Icon Options
Adding: when the tooltip is using
{ direction: 'left' }
, the x coordinate oftooltipAnchor
is inverted.2.) Tooltip
Adding
{ direction: 'left' }
to that list.3.) Tooltip Options
Adding: when the tooltip is using
{ direction: 'left' }
, the x coordinate ofoffset
is inverted.