File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
src/renderers/dom/client/eventPlugins Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -642,7 +642,7 @@ var SimpleEventPlugin = {
642642 // fire. The workaround for this bug involves attaching an empty click
643643 // listener on the target node.
644644 // http://www.quirksmode.org/blog/archives/2010/09/click_event_del.html
645- if ( registrationName === 'onClick' && isInteractive ( inst . _tag ) ) {
645+ if ( registrationName === 'onClick' && ! isInteractive ( inst . _tag ) ) {
646646 var key = getDictionaryKey ( inst ) ;
647647 var node = ReactDOMComponentTree . getNodeFromInstance ( inst ) ;
648648 if ( ! onClickListeners [ key ] ) {
@@ -656,7 +656,7 @@ var SimpleEventPlugin = {
656656 } ,
657657
658658 willDeleteListener : function ( inst , registrationName ) {
659- if ( registrationName === 'onClick' && isInteractive ( inst . _tag ) ) {
659+ if ( registrationName === 'onClick' && ! isInteractive ( inst . _tag ) ) {
660660 var key = getDictionaryKey ( inst ) ;
661661 onClickListeners [ key ] . remove ( ) ;
662662 delete onClickListeners [ key ] ;
Original file line number Diff line number Diff line change @@ -119,4 +119,37 @@ describe('SimpleEventPlugin', function() {
119119 } ) ;
120120 } ) ;
121121 } ) ;
122+
123+
124+ describe ( 'iOS bubbling click fix' , function ( ) {
125+ // See http://www.quirksmode.org/blog/archives/2010/09/click_event_del.html
126+
127+ beforeEach ( function ( ) {
128+ onClick . mockClear ( ) ;
129+ } ) ;
130+
131+ it ( 'does not add a local click to interactive elements' , function ( ) {
132+ var container = document . createElement ( 'div' ) ;
133+
134+ ReactDOM . render ( < button onClick = { onClick } > </ button > , container ) ;
135+
136+ var node = container . firstChild ;
137+
138+ node . dispatchEvent ( new MouseEvent ( 'click' ) ) ;
139+
140+ expect ( onClick . mock . calls . length ) . toBe ( 0 ) ;
141+ } ) ;
142+
143+ it ( 'adds a local click listener to non-interactive elements' , function ( ) {
144+ var container = document . createElement ( 'div' ) ;
145+
146+ ReactDOM . render ( < div onClick = { onClick } > </ div > , container ) ;
147+
148+ var node = container . firstChild ;
149+
150+ node . dispatchEvent ( new MouseEvent ( 'click' ) ) ;
151+
152+ expect ( onClick . mock . calls . length ) . toBe ( 0 ) ;
153+ } ) ;
154+ } ) ;
122155} ) ;
You can’t perform that action at this time.
0 commit comments