@@ -191,12 +191,29 @@ exports.default = function (target) {
191191 dispatchGlobalEvent ( _constant2 . default . GLOBAL . REBUILD ) ;
192192 } ;
193193
194+ /**
195+ * Show specific tooltip
196+ * @trigger ReactTooltip.show()
197+ */
198+ target . show = function ( target ) {
199+ dispatchGlobalEvent ( _constant2 . default . GLOBAL . SHOW , { target : target } ) ;
200+ } ;
201+
194202 target . prototype . globalRebuild = function ( ) {
195203 if ( this . mount ) {
196204 this . unbindListener ( ) ;
197205 this . bindListener ( ) ;
198206 }
199207 } ;
208+
209+ target . prototype . globalShow = function ( event ) {
210+ if ( this . mount ) {
211+ // Create a fake event, specific show will limit the type to `solid`
212+ // only `float` type cares e.clientX e.clientY
213+ var e = { currentTarget : event . detail . target } ;
214+ this . showTooltip ( e , true ) ;
215+ }
216+ } ;
200217} ;
201218
202219var _constant = require ( '../constant' ) ;
@@ -205,16 +222,16 @@ var _constant2 = _interopRequireDefault(_constant);
205222
206223function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
207224
208- var dispatchGlobalEvent = function dispatchGlobalEvent ( eventName ) {
225+ var dispatchGlobalEvent = function dispatchGlobalEvent ( eventName , opts ) {
209226 // Compatibale with IE
210227 // @see http://stackoverflow.com/questions/26596123/internet-explorer-9-10-11-event-constructor-doesnt-work
211228 var event = void 0 ;
212229
213- if ( typeof window . Event === 'function' ) {
214- event = new window . Event ( eventName ) ;
230+ if ( typeof window . CustomEvent === 'function' ) {
231+ event = new window . CustomEvent ( eventName , { detail : opts } ) ;
215232 } else {
216233 event = document . createEvent ( 'Event' ) ;
217- event . initEvent ( eventName , false , true ) ;
234+ event . initEvent ( eventName , false , true , opts ) ;
218235 }
219236
220237 window . dispatchEvent ( event ) ;
@@ -239,6 +256,10 @@ exports.default = function (target) {
239256 window . removeEventListener ( _constant2 . default . GLOBAL . REBUILD , this . globalRebuild ) ;
240257 window . addEventListener ( _constant2 . default . GLOBAL . REBUILD , this . globalRebuild , false ) ;
241258
259+ // ReactTooltip.show
260+ window . removeEventListener ( _constant2 . default . GLOBAL . SHOW , this . globalShow ) ;
261+ window . addEventListener ( _constant2 . default . GLOBAL . SHOW , this . globalShow , false ) ;
262+
242263 // Resize
243264 window . removeEventListener ( 'resize' , this . onWindowResize ) ;
244265 window . addEventListener ( 'resize' , this . onWindowResize , false ) ;
@@ -247,6 +268,7 @@ exports.default = function (target) {
247268 target . prototype . unbindWindowEvents = function ( ) {
248269 window . removeEventListener ( _constant2 . default . GLOBAL . HIDE , this . hideTooltip ) ;
249270 window . removeEventListener ( _constant2 . default . GLOBAL . REBUILD , this . globalRebuild ) ;
271+ window . removeEventListener ( _constant2 . default . GLOBAL . SHOW , this . globalShow ) ;
250272 window . removeEventListener ( 'resize' , this . onWindowResize ) ;
251273 } ;
252274
@@ -361,7 +383,7 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
361383 ariaProps : ( 0 , _aria . parseAria ) ( props ) // aria- and role attributes
362384 } ;
363385
364- _this . bind ( [ 'showTooltip' , 'updateTooltip' , 'hideTooltip' , 'globalRebuild' , 'onWindowResize' ] ) ;
386+ _this . bind ( [ 'showTooltip' , 'updateTooltip' , 'hideTooltip' , 'globalRebuild' , 'globalShow' , ' onWindowResize'] ) ;
365387
366388 _this . mount = true ;
367389 _this . delayShowLoop = null ;
@@ -525,9 +547,17 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
525547
526548 } , {
527549 key : 'showTooltip' ,
528- value : function showTooltip ( e ) {
550+ value : function showTooltip ( e , isGlobalCall ) {
529551 var _this5 = this ;
530552
553+ if ( isGlobalCall ) {
554+ // Don't trigger other elements belongs to other ReactTooltip
555+ var targetArray = this . getTargetArray ( this . props . id ) ;
556+ var isMyElement = targetArray . some ( function ( ele ) {
557+ return ele === e . currentTarget ;
558+ } ) ;
559+ if ( ! isMyElement || this . state . show ) return ;
560+ }
531561 // Get the tooltip content
532562 // calculate in this phrase so that tip width height can be detected
533563 var _props3 = this . props ;
@@ -549,13 +579,13 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
549579 }
550580 var placeholder = ( 0 , _getTipContent2 . default ) ( originTooltip , content , isMultiline ) ;
551581
552- // If it is focus event, switch to `solid` effect
553- var isFocus = e instanceof window . FocusEvent ;
582+ // If it is focus event or called by ReactTooltip.show , switch to `solid` effect
583+ var switchToSolid = e instanceof window . FocusEvent || isGlobalCall ;
554584 this . setState ( {
555585 placeholder : placeholder ,
556586 place : e . currentTarget . getAttribute ( 'data-place' ) || this . props . place || 'top' ,
557587 type : e . currentTarget . getAttribute ( 'data-type' ) || this . props . type || 'dark' ,
558- effect : isFocus && 'solid' || e . currentTarget . getAttribute ( 'data-effect' ) || this . props . effect || 'float' ,
588+ effect : switchToSolid && 'solid' || e . currentTarget . getAttribute ( 'data-effect' ) || this . props . effect || 'float' ,
559589 offset : e . currentTarget . getAttribute ( 'data-offset' ) || this . props . offset || { } ,
560590 html : e . currentTarget . getAttribute ( 'data-html' ) ? e . currentTarget . getAttribute ( 'data-html' ) === 'true' : this . props . html || false ,
561591 delayShow : e . currentTarget . getAttribute ( 'data-delay-show' ) || this . props . delayShow || 0 ,
@@ -1128,7 +1158,7 @@ var calculateOffset = function calculateOffset(offset) {
11281158var getParent = function getParent ( currentTarget ) {
11291159 var currentParent = currentTarget ;
11301160 while ( currentParent ) {
1131- if ( currentParent . style . transform . length > 0 ) break ;
1161+ if ( window . getComputedStyle ( currentParent ) . getPropertyValue ( ' transform' ) !== 'none' ) break ;
11321162 currentParent = currentParent . parentElement ;
11331163 }
11341164
0 commit comments