Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't rename gotpointercapture and lostpointercapture events #4096

Merged
merged 4 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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$/, ''));
}
rschristian marked this conversation as resolved.
Show resolved Hide resolved

// 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');
});
});
Loading