Skip to content

Commit c6323cb

Browse files
committed
Duck type fibers to check for disable prop
1 parent 2f01751 commit c6323cb

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

scripts/fiber/tests-failing.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,6 @@ src/renderers/dom/shared/__tests__/ReactEventIndependence-test.js
5555
src/renderers/dom/shared/__tests__/ReactEventListener-test.js
5656
* should batch between handlers from different roots
5757

58-
src/renderers/dom/shared/eventPlugins/__tests__/SimpleEventPlugin-test.js
59-
* should not forward clicks when it starts out disabled
60-
* should not forward clicks when it becomes disabled
61-
* should not forward clicks when it starts out disabled
62-
* should not forward clicks when it becomes disabled
63-
* should not forward clicks when it starts out disabled
64-
* should not forward clicks when it becomes disabled
65-
* should not forward clicks when it starts out disabled
66-
* should not forward clicks when it becomes disabled
67-
6858
src/renderers/dom/shared/wrappers/__tests__/ReactDOMInput-test.js
6959
* should control a value in reentrant events
7060

scripts/fiber/tests-passing.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,16 +706,24 @@ src/renderers/dom/shared/eventPlugins/__tests__/SimpleEventPlugin-test.js
706706
* A non-interactive tags click when disabled
707707
* A non-interactive tags clicks bubble when disabled
708708
* should forward clicks when it starts out not disabled
709+
* should not forward clicks when it starts out disabled
709710
* should forward clicks when it becomes not disabled
711+
* should not forward clicks when it becomes disabled
710712
* should work correctly if the listener is changed
711713
* should forward clicks when it starts out not disabled
714+
* should not forward clicks when it starts out disabled
712715
* should forward clicks when it becomes not disabled
716+
* should not forward clicks when it becomes disabled
713717
* should work correctly if the listener is changed
714718
* should forward clicks when it starts out not disabled
719+
* should not forward clicks when it starts out disabled
715720
* should forward clicks when it becomes not disabled
721+
* should not forward clicks when it becomes disabled
716722
* should work correctly if the listener is changed
717723
* should forward clicks when it starts out not disabled
724+
* should not forward clicks when it starts out disabled
718725
* should forward clicks when it becomes not disabled
726+
* should not forward clicks when it becomes disabled
719727
* should work correctly if the listener is changed
720728
* does not add a local click to interactive elements
721729
* adds a local click listener to non-interactive elements

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
'use strict';
1414

15+
import type { Fiber } from 'ReactFiber';
16+
1517
var EventPropagators = require('EventPropagators');
1618
var SyntheticAnimationEvent = require('SyntheticAnimationEvent');
1719
var SyntheticClipboardEvent = require('SyntheticClipboardEvent');
@@ -145,12 +147,23 @@ function isInteractive(tag) {
145147
);
146148
}
147149

148-
function shouldPreventMouseEvent(inst) {
150+
function shouldPreventMouseEvent(inst : ReactInstance | Fiber) {
149151
if (inst) {
150-
var disabled = inst._currentElement && inst._currentElement.props.disabled;
151-
152-
if (disabled) {
153-
return isInteractive(inst._tag);
152+
if (typeof inst.tag === 'number') {
153+
// TODO: This is only safe if this is the current Fiber but TreeTraversal
154+
// is not currently guaranteed to give us the current instance.
155+
const fiber = (inst : any);
156+
const disabled = fiber.memoizedProps.disabled;
157+
if (disabled) {
158+
return isInteractive(fiber.type);
159+
}
160+
} else {
161+
const internalInstance : ReactInstance = (inst : any);
162+
const disabled = internalInstance._currentElement &&
163+
internalInstance._currentElement.props.disabled;
164+
if (disabled) {
165+
return isInteractive(internalInstance._tag);
166+
}
154167
}
155168
}
156169

@@ -163,7 +176,7 @@ var SimpleEventPlugin: PluginModule<MouseEvent> = {
163176

164177
extractEvents: function(
165178
topLevelType: TopLevelTypes,
166-
targetInst: ReactInstance,
179+
targetInst: ReactInstance | Fiber,
167180
nativeEvent: MouseEvent,
168181
nativeEventTarget: EventTarget,
169182
): null | ReactSyntheticEvent {

0 commit comments

Comments
 (0)