Skip to content

Commit 98fb678

Browse files
hpneoJoviDeCroock
andauthored
Normalize CompositionEvent listeners in preact/compat (#3430)
Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
1 parent 41f9b4b commit 98fb678

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

compat/src/render.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ options.vnode = vnode => {
123123
if (IS_DOM && i === 'children' && type === 'noscript') {
124124
// Emulate React's behavior of not rendering the contents of noscript tags on the client.
125125
continue;
126-
}
127-
else if (i === 'value' && 'defaultValue' in props && value == null) {
126+
} else if (i === 'value' && 'defaultValue' in props && value == null) {
128127
// Skip applying value if it is null/undefined and we already set
129128
// a default value
130129
continue;
@@ -154,7 +153,7 @@ options.vnode = vnode => {
154153
i = 'onfocusin';
155154
} else if (/^onblur$/i.test(i)) {
156155
i = 'onfocusout';
157-
} else if (/^on(Ani|Tra|Tou|BeforeInp)/.test(i)) {
156+
} else if (/^on(Ani|Tra|Tou|BeforeInp|Compo)/.test(i)) {
158157
i = i.toLowerCase();
159158
} else if (nonCustomElement && CAMEL_PROPS.test(i)) {
160159
i = i.replace(/[A-Z0-9]/, '-$&').toLowerCase();

compat/test/browser/events.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,11 @@ describe('preact/compat events', () => {
275275
scratch.firstChild.dispatchEvent(createEvent('beforeinput'));
276276
expect(spy).to.be.calledOnce;
277277
});
278+
279+
it('should normalize compositionstart event listener', () => {
280+
let spy = sinon.spy();
281+
render(<input onCompositionStart={spy} />, scratch);
282+
scratch.firstChild.dispatchEvent(createEvent('compositionstart'));
283+
expect(spy).to.be.calledOnce;
284+
});
278285
});

0 commit comments

Comments
 (0)