Skip to content

Commit

Permalink
Merge pull request #4096 from preactjs/fix/pointer-capture-event-list…
Browse files Browse the repository at this point in the history
…eners

fix: Don't rename `gotpointercapture` and `lostpointercapture` events
  • Loading branch information
rschristian committed Aug 15, 2023
2 parents 19b3b1b + c1ca65b commit 7cd4833
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/diff/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ export function setProperty(dom, name, value, oldValue, isSvg) {
}
// Benchmark for comparison: https://esbench.com/bench/574c954bdb965b9a00965ac6
else if (name[0] === 'o' && name[1] === 'n') {
useCapture = name !== (name = name.replace(/Capture$/, ''));
if (/PointerCapture$/.test(name)) {
useCapture = false;
} else {
useCapture = name !== (name = name.replace(/Capture$/, ''));
}

// Infer correct casing for DOM built-in events:
if (name.toLowerCase() in dom) name = name.toLowerCase().slice(2);
Expand Down
34 changes: 34 additions & 0 deletions test/browser/events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,38 @@ describe('event handling', () => {
expect(click, 'click').to.have.been.calledOnce;
});
}

// Uniquely named in that the base event names end with 'Capture'
it('should support (got|lost)PointerCapture events', () => {
let gotPointerCapture = sinon.spy(),
gotPointerCaptureCapture = sinon.spy(),
lostPointerCapture = sinon.spy(),
lostPointerCaptureCapture = sinon.spy();

render(
<div
onGotPointerCapture={gotPointerCapture}
onLostPointerCapture={lostPointerCapture}
/>,
scratch
);

expect(proto.addEventListener)
.to.have.been.calledTwice.and.to.have.been.calledWith('gotpointercapture')
.and.calledWith('lostpointercapture');

proto.addEventListener.resetHistory();

render(
<div
onGotPointerCaptureCapture={gotPointerCaptureCapture}
onLostPointerCaptureCapture={lostPointerCaptureCapture}
/>,
scratch
);

expect(proto.addEventListener)
.to.have.been.calledTwice.and.to.have.been.calledWith('gotpointercapture')
.and.calledWith('lostpointercapture');
});
});

0 comments on commit 7cd4833

Please sign in to comment.