From aec15a633ea9c5d6be783977cb1f78abfa2df45b Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Fri, 29 Dec 2023 08:36:13 +0100 Subject: [PATCH] ensure we are able to support capture events from compat --- compat/test/browser/events.test.js | 23 ++++++++++++++++++++++- src/diff/props.js | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/compat/test/browser/events.test.js b/compat/test/browser/events.test.js index b7a9d1d7fe..d59dbef8ed 100644 --- a/compat/test/browser/events.test.js +++ b/compat/test/browser/events.test.js @@ -2,7 +2,8 @@ import { render } from 'preact'; import { setupScratch, teardown, - createEvent + createEvent, + supportsPassiveEvents } from '../../../test/_util/helpers'; import React, { createElement } from 'preact/compat'; @@ -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( +
+ +
, + scratch + ); + + expect(proto.addEventListener).to.have.been.calledOnce; + expect(proto.addEventListener).to.have.been.calledWithExactly( + 'touchmove', + sinon.match.func, + true + ); + }); + } }); diff --git a/src/diff/props.js b/src/diff/props.js index 6421330bd0..3ec7e91141 100644 --- a/src/diff/props.js +++ b/src/diff/props.js @@ -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);