Skip to content

Commit

Permalink
Remove interactive element filter from SimpleEventPlugin, move over t…
Browse files Browse the repository at this point in the history
…o tree traversal
  • Loading branch information
nhunzaker committed Nov 19, 2016
1 parent 5a9a611 commit 2ccd14e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
22 changes: 0 additions & 22 deletions src/renderers/dom/shared/eventPlugins/SimpleEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,6 @@ var topLevelEventsToDispatchConfig: {[key: TopLevelTypes]: DispatchConfig} = {};
topLevelEventsToDispatchConfig[topEvent] = type;
});

function isInteractive(tag) {
return (
tag === 'BUTTON' || tag === 'INPUT' ||
tag === 'SELECT' || tag === 'TEXTAREA'
);
}

function shouldPreventMouseEvent(node) {
if (node) {
if (node.disabled) {
return isInteractive(node.tagName)
}
}

return false;
}

var SimpleEventPlugin: PluginModule<MouseEvent> = {

eventTypes: eventTypes,
Expand Down Expand Up @@ -230,11 +213,6 @@ var SimpleEventPlugin: PluginModule<MouseEvent> = {
case 'topMouseDown':
case 'topMouseMove':
case 'topMouseUp':
// Disabled elements should not respond to mouse events
if (shouldPreventMouseEvent(nativeEventTarget)) {
return null;
}
/* falls through */
case 'topMouseOut':
case 'topMouseOver':
case 'topContextMenu':
Expand Down
18 changes: 12 additions & 6 deletions src/renderers/shared/shared/ReactTreeTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,27 @@ function shouldIgnoreElement(inst) {
}

function traverseTwoPhase(inst, fn, arg) {
// Do not traverse an tree that originates with a disabled
// element
if (shouldIgnoreElement(inst)) {
return
}

var path = [];
while (inst) {
path.push(inst);
inst = getParent(inst);
}

var i;
var disabledParent = false;
var disabled = false;
// walking from parent to child
for (i = path.length; i-- > 0;) {
// Check to see if we are within a disabled tree
disabledParent = disabledParent || shouldIgnoreElement(path[i])
// If we are within a disabled tree, and the current element
// is active, remove the item from the tree
if (disabledParent && isInteractive(path[i])) {
// Are we currently, our about to be, within a disabled tree
disabled = disabled || shouldIgnoreElement(path[i])
// If so, remove the current element from traversion if it
// is interactive
if (disabled && isInteractive(path[i])) {
path.splice(i, 1);
}
}
Expand Down

0 comments on commit 2ccd14e

Please sign in to comment.