tooltip icon indicating copy to clipboard operation
tooltip copied to clipboard

Rethink position, attach, detach, show, and hide methods

Open darsain opened this issue 10 years ago • 1 comments

Current proposal

#position(x, y) , #position(element)

Should only re-position the tooltip to x,y coordinates, or element. It shouldn't do any attaching under the hood, and should be oblivious to any active attachment.

#attach(target)

Should attach the tooltip to various things, and set up the most appropriate automatic re-positioning for given target:

  • element - should update on window resize and scroll
  • cursor - should update on cursor movement

All updates obviously throttled by rAF.

#detach()

Should cancel active attachment, and remove the tooltip from listeners.

#show()

Currently does too many things. Re-positions stuff when tooltip is attached, make this._aware() calls.

Ideally it should only attach tooltip element to body, and set this.hidden flag to false. Possibly notify attached target watchers about a change so they reposition the tip? Sounds too convoluted :/

Needs more thought.

#hide()

Ideally should only set the this.hidden flag to true, and remove tooltip element from DOM.

Currently, it does calls to this._unaware() which should be removed altogether.

Issues

  • When tooltip is hidden, re-positioning doesn't happen. In this state the attachment target might change position. Than when #show() is called, tooltip will be at the wrong place.
  • #show() is currently doing #position(this._attachedTo) when tooltip is attached. This won't work, or be horrible when #attach('cursor') is implemented.

darsain avatar Mar 11 '15 15:03 darsain

Or, a quite different API rethink altogether:

  1. Remove show/hide methods, replace with only one, #destroy().
  2. There is no concept of hidden tooltip anymore.
  3. Tooltip either exists, and is visible, or it doesn't.

This will force developers to never hide tooltips, or keep Tooltip instances that are hidden. They'll just be discarded, releasing the memory.

Gonna look for reasons why this is a bad idea :)

darsain avatar Aug 08 '15 20:08 darsain