Skip to content

Commit

Permalink
Normalize CompositionEvent listeners in preact/compat (#3430)
Browse files Browse the repository at this point in the history
Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
  • Loading branch information
hpneo and JoviDeCroock committed Jan 26, 2022
1 parent 41f9b4b commit 98fb678
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions compat/src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ options.vnode = vnode => {
if (IS_DOM && i === 'children' && type === 'noscript') {
// Emulate React's behavior of not rendering the contents of noscript tags on the client.
continue;
}
else if (i === 'value' && 'defaultValue' in props && value == null) {
} else if (i === 'value' && 'defaultValue' in props && value == null) {
// Skip applying value if it is null/undefined and we already set
// a default value
continue;
Expand Down Expand Up @@ -154,7 +153,7 @@ options.vnode = vnode => {
i = 'onfocusin';
} else if (/^onblur$/i.test(i)) {
i = 'onfocusout';
} else if (/^on(Ani|Tra|Tou|BeforeInp)/.test(i)) {
} else if (/^on(Ani|Tra|Tou|BeforeInp|Compo)/.test(i)) {
i = i.toLowerCase();
} else if (nonCustomElement && CAMEL_PROPS.test(i)) {
i = i.replace(/[A-Z0-9]/, '-$&').toLowerCase();
Expand Down
7 changes: 7 additions & 0 deletions compat/test/browser/events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,11 @@ describe('preact/compat events', () => {
scratch.firstChild.dispatchEvent(createEvent('beforeinput'));
expect(spy).to.be.calledOnce;
});

it('should normalize compositionstart event listener', () => {
let spy = sinon.spy();
render(<input onCompositionStart={spy} />, scratch);
scratch.firstChild.dispatchEvent(createEvent('compositionstart'));
expect(spy).to.be.calledOnce;
});
});

0 comments on commit 98fb678

Please sign in to comment.