From 7fd68452d731aaddbdce7fcb4d50f61d23b218c8 Mon Sep 17 00:00:00 2001 From: Nathan Hunzaker Date: Thu, 17 Nov 2016 08:31:21 -0500 Subject: [PATCH] Do not extract mouse events for children of disabled parents --- .../dom/client/eventPlugins/SimpleEventPlugin.js | 10 +++++++--- .../eventPlugins/__tests__/SimpleEventPlugin-test.js | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/renderers/dom/client/eventPlugins/SimpleEventPlugin.js b/src/renderers/dom/client/eventPlugins/SimpleEventPlugin.js index 5b30244cc648d9..fb467dd886751d 100644 --- a/src/renderers/dom/client/eventPlugins/SimpleEventPlugin.js +++ b/src/renderers/dom/client/eventPlugins/SimpleEventPlugin.js @@ -158,10 +158,14 @@ function isInteractive(tag) { function shouldPreventMouseEvent(inst) { if (inst) { - var disabled = inst._currentElement && inst._currentElement.props.disabled; + var focus = inst; - if (disabled) { - return isInteractive(inst._tag); + while (focus) { + if (focus._currentElement && focus._currentElement.props.disabled) { + return isInteractive(focus._tag); + } + + focus = focus._hostParent; } } diff --git a/src/renderers/dom/client/eventPlugins/__tests__/SimpleEventPlugin-test.js b/src/renderers/dom/client/eventPlugins/__tests__/SimpleEventPlugin-test.js index d8f30633d10bbf..6cea83723d8e81 100644 --- a/src/renderers/dom/client/eventPlugins/__tests__/SimpleEventPlugin-test.js +++ b/src/renderers/dom/client/eventPlugins/__tests__/SimpleEventPlugin-test.js @@ -58,6 +58,17 @@ describe('SimpleEventPlugin', function() { expect(onClick.mock.calls.length).toBe(1); }); + it('clicking a child of a disabled element does not register a click', function() { + var element = ReactTestUtils.renderIntoDocument( + + ); + var child = ReactDOM.findDOMNode(element).querySelector('span'); + + onClick.mockClear(); + ReactTestUtils.SimulateNative.click(child); + expect(onClick.mock.calls.length).toBe(0); + }); + ['button', 'input', 'select', 'textarea'].forEach(function(tagName) { describe(tagName, function() {