Skip to content

Commit

Permalink
Do not extract mouse events for children of disabled parents
Browse files Browse the repository at this point in the history
  • Loading branch information
nhunzaker committed Nov 17, 2016
1 parent 04447d3 commit 7fd6845
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/renderers/dom/client/eventPlugins/SimpleEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<button onClick={onClick} disabled><span /></button>
);
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() {
Expand Down

0 comments on commit 7fd6845

Please sign in to comment.