Skip to content

Commit

Permalink
Merge pull request #2380 from 38elements/isPropagationStopped
Browse files Browse the repository at this point in the history
Fix event.isPropagationStopped()
  • Loading branch information
marvinhagemeister authored Mar 1, 2020
2 parents b565b5a + 3e7d5ab commit c8bfb3c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compat/src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ options.event = e => {
if (oldEventHook) e = oldEventHook(e);
e.persist = () => {};
e.isDefaultPrevented = () => e.defaultPrevented;
e.isPropagationStopped = () => e.stopPropagation;
const normalStopPropagation = e.stopPropagation;
let stoppedPropagating = false;
e.stopPropagation = function() {
stoppedPropagating = true;
normalStopPropagation.call(this);
};
e.isPropagationStopped = () => stoppedPropagating;
return (e.nativeEvent = e);
};

Expand Down
8 changes: 8 additions & 0 deletions compat/test/browser/events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ describe('preact/compat events', () => {
expect(() => event.persist()).to.not.throw();
expect(() => event.isDefaultPrevented()).to.not.throw();
expect(() => event.isPropagationStopped()).to.not.throw();

expect(event.isDefaultPrevented()).to.be.false;
event.preventDefault();
expect(event.isDefaultPrevented()).to.be.true;

expect(event.isPropagationStopped()).to.be.false;
event.stopPropagation();
expect(event.isPropagationStopped()).to.be.true;
});

it('should normalize ondoubleclick event', () => {
Expand Down

0 comments on commit c8bfb3c

Please sign in to comment.