Skip to content

Commit

Permalink
ensure we are able to support capture events from compat (#4243)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jan 2, 2024
1 parent 899e9d9 commit 13b0afb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
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

0 comments on commit 13b0afb

Please sign in to comment.