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

ensure we are able to support capture events from compat #4243

Merged
merged 2 commits into from
Jan 2, 2024
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
23 changes: 22 additions & 1 deletion compat/test/browser/events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { render } from 'preact';
import {
setupScratch,
teardown,
createEvent
createEvent,
supportsPassiveEvents
} from '../../../test/_util/helpers';

import React, { createElement } from 'preact/compat';
Expand Down Expand Up @@ -309,4 +310,24 @@ describe('preact/compat events', () => {
scratch.firstChild.dispatchEvent(createEvent('focusout'));
expect(spy).to.be.calledOnce;
});

if (supportsPassiveEvents()) {
it('should use capturing for event props ending with *Capture', () => {
let click = sinon.spy();

render(
<div onTouchMoveCapture={click}>
<button type="button">Click me</button>
</div>,
scratch
);

expect(proto.addEventListener).to.have.been.calledOnce;
expect(proto.addEventListener).to.have.been.calledWithExactly(
'touchmove',
sinon.match.func,
true
);
});
}
});
2 changes: 1 addition & 1 deletion src/diff/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ 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(/(PointerCapture)$|Capture$/, '$1'));
name !== (name = name.replace(/(PointerCapture)$|Capture$/i, '$1'));

// Infer correct casing for DOM built-in events:
if (name.toLowerCase() in dom) name = name.toLowerCase().slice(2);
Expand Down
Loading