Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed Sep 18, 2019
1 parent 94a4374 commit 32d1728
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/react-dom/src/events/DOMEventResponderSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ function validateEventValue(eventValue: any): void {
);
}
};
eventValue.isDefaultPrevented = () => {
if (__DEV__) {
showWarning('isDefaultPrevented()');
}
};
eventValue.isPropagationStopped = () => {
if (__DEV__) {
showWarning('isPropagationStopped()');
}
};
// $FlowFixMe: we don't need value, Flow thinks we do
Object.defineProperty(eventValue, 'nativeEvent', {
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,30 @@ describe('DOMEventResponderSystem', () => {
</button>
);
};
expect(() => {
handler = event => {
event.isDefaultPrevented();
};
ReactDOM.render(<Test />, container);
dispatchClickEvent(buttonRef.current);
}).toWarnDev(
'Warning: isDefaultPrevented() is not available on event objects created from event responder modules ' +
'(React Flare).' +
' Try wrapping in a conditional, i.e. `if (event.type !== "press") { event.isDefaultPrevented() }`',
{withoutStack: true},
);
expect(() => {
handler = event => {
event.isPropagationStopped();
};
ReactDOM.render(<Test />, container);
dispatchClickEvent(buttonRef.current);
}).toWarnDev(
'Warning: isPropagationStopped() is not available on event objects created from event responder modules ' +
'(React Flare).' +
' Try wrapping in a conditional, i.e. `if (event.type !== "press") { event.isPropagationStopped() }`',
{withoutStack: true},
);
expect(() => {
handler = event => {
return event.nativeEvent;
Expand Down

0 comments on commit 32d1728

Please sign in to comment.