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

Normalize CompositionEvent listeners in preact/compat #3430

Merged
merged 2 commits into from
Jan 26, 2022
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
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;
});
});