@@ -191,12 +191,29 @@ exports.default = function (target) {
191
191
dispatchGlobalEvent ( _constant2 . default . GLOBAL . REBUILD ) ;
192
192
} ;
193
193
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
+
194
202
target . prototype . globalRebuild = function ( ) {
195
203
if ( this . mount ) {
196
204
this . unbindListener ( ) ;
197
205
this . bindListener ( ) ;
198
206
}
199
207
} ;
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
+ } ;
200
217
} ;
201
218
202
219
var _constant = require ( '../constant' ) ;
@@ -205,16 +222,16 @@ var _constant2 = _interopRequireDefault(_constant);
205
222
206
223
function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
207
224
208
- var dispatchGlobalEvent = function dispatchGlobalEvent ( eventName ) {
225
+ var dispatchGlobalEvent = function dispatchGlobalEvent ( eventName , opts ) {
209
226
// Compatibale with IE
210
227
// @see http://stackoverflow.com/questions/26596123/internet-explorer-9-10-11-event-constructor-doesnt-work
211
228
var event = void 0 ;
212
229
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 } ) ;
215
232
} else {
216
233
event = document . createEvent ( 'Event' ) ;
217
- event . initEvent ( eventName , false , true ) ;
234
+ event . initEvent ( eventName , false , true , opts ) ;
218
235
}
219
236
220
237
window . dispatchEvent ( event ) ;
@@ -239,6 +256,10 @@ exports.default = function (target) {
239
256
window . removeEventListener ( _constant2 . default . GLOBAL . REBUILD , this . globalRebuild ) ;
240
257
window . addEventListener ( _constant2 . default . GLOBAL . REBUILD , this . globalRebuild , false ) ;
241
258
259
+ // ReactTooltip.show
260
+ window . removeEventListener ( _constant2 . default . GLOBAL . SHOW , this . globalShow ) ;
261
+ window . addEventListener ( _constant2 . default . GLOBAL . SHOW , this . globalShow , false ) ;
262
+
242
263
// Resize
243
264
window . removeEventListener ( 'resize' , this . onWindowResize ) ;
244
265
window . addEventListener ( 'resize' , this . onWindowResize , false ) ;
@@ -247,6 +268,7 @@ exports.default = function (target) {
247
268
target . prototype . unbindWindowEvents = function ( ) {
248
269
window . removeEventListener ( _constant2 . default . GLOBAL . HIDE , this . hideTooltip ) ;
249
270
window . removeEventListener ( _constant2 . default . GLOBAL . REBUILD , this . globalRebuild ) ;
271
+ window . removeEventListener ( _constant2 . default . GLOBAL . SHOW , this . globalShow ) ;
250
272
window . removeEventListener ( 'resize' , this . onWindowResize ) ;
251
273
} ;
252
274
@@ -361,7 +383,7 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
361
383
ariaProps : ( 0 , _aria . parseAria ) ( props ) // aria- and role attributes
362
384
} ;
363
385
364
- _this . bind ( [ 'showTooltip' , 'updateTooltip' , 'hideTooltip' , 'globalRebuild' , 'onWindowResize' ] ) ;
386
+ _this . bind ( [ 'showTooltip' , 'updateTooltip' , 'hideTooltip' , 'globalRebuild' , 'globalShow' , ' onWindowResize'] ) ;
365
387
366
388
_this . mount = true ;
367
389
_this . delayShowLoop = null ;
@@ -525,9 +547,17 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
525
547
526
548
} , {
527
549
key : 'showTooltip' ,
528
- value : function showTooltip ( e ) {
550
+ value : function showTooltip ( e , isGlobalCall ) {
529
551
var _this5 = this ;
530
552
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
+ }
531
561
// Get the tooltip content
532
562
// calculate in this phrase so that tip width height can be detected
533
563
var _props3 = this . props ;
@@ -549,13 +579,13 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
549
579
}
550
580
var placeholder = ( 0 , _getTipContent2 . default ) ( originTooltip , content , isMultiline ) ;
551
581
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 ;
554
584
this . setState ( {
555
585
placeholder : placeholder ,
556
586
place : e . currentTarget . getAttribute ( 'data-place' ) || this . props . place || 'top' ,
557
587
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' ,
559
589
offset : e . currentTarget . getAttribute ( 'data-offset' ) || this . props . offset || { } ,
560
590
html : e . currentTarget . getAttribute ( 'data-html' ) ? e . currentTarget . getAttribute ( 'data-html' ) === 'true' : this . props . html || false ,
561
591
delayShow : e . currentTarget . getAttribute ( 'data-delay-show' ) || this . props . delayShow || 0 ,
@@ -1128,7 +1158,7 @@ var calculateOffset = function calculateOffset(offset) {
1128
1158
var getParent = function getParent ( currentTarget ) {
1129
1159
var currentParent = currentTarget ;
1130
1160
while ( currentParent ) {
1131
- if ( currentParent . style . transform . length > 0 ) break ;
1161
+ if ( window . getComputedStyle ( currentParent ) . getPropertyValue ( ' transform' ) !== 'none' ) break ;
1132
1162
currentParent = currentParent . parentElement ;
1133
1163
}
1134
1164
0 commit comments