Skip to content

Commit 7fd6845

Browse files
committed
Do not extract mouse events for children of disabled parents
1 parent 04447d3 commit 7fd6845

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/renderers/dom/client/eventPlugins/SimpleEventPlugin.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,14 @@ function isInteractive(tag) {
158158

159159
function shouldPreventMouseEvent(inst) {
160160
if (inst) {
161-
var disabled = inst._currentElement && inst._currentElement.props.disabled;
161+
var focus = inst;
162162

163-
if (disabled) {
164-
return isInteractive(inst._tag);
163+
while (focus) {
164+
if (focus._currentElement && focus._currentElement.props.disabled) {
165+
return isInteractive(focus._tag);
166+
}
167+
168+
focus = focus._hostParent;
165169
}
166170
}
167171

src/renderers/dom/client/eventPlugins/__tests__/SimpleEventPlugin-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ describe('SimpleEventPlugin', function() {
5858
expect(onClick.mock.calls.length).toBe(1);
5959
});
6060

61+
it('clicking a child of a disabled element does not register a click', function() {
62+
var element = ReactTestUtils.renderIntoDocument(
63+
<button onClick={onClick} disabled><span /></button>
64+
);
65+
var child = ReactDOM.findDOMNode(element).querySelector('span');
66+
67+
onClick.mockClear();
68+
ReactTestUtils.SimulateNative.click(child);
69+
expect(onClick.mock.calls.length).toBe(0);
70+
});
71+
6172
['button', 'input', 'select', 'textarea'].forEach(function(tagName) {
6273

6374
describe(tagName, function() {

0 commit comments

Comments
 (0)