Skip to content

Commit

Permalink
Merge pull request #1366 from developit/before_input
Browse files Browse the repository at this point in the history
Add edge case for beforeinput event
  • Loading branch information
marvinhagemeister committed Mar 11, 2019
2 parents dc2e810 + ee3b692 commit 558fa70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compat/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ function applyEventNormalization({ type, props }) {
props.ondblclick = props[newProps.ondoubleclick];
delete props[newProps.ondoubleclick];
}
if (newProps.onbeforeinput) {
props.onbeforeinput = props[newProps.onbeforeinput];
delete props[newProps.onbeforeinput];
}
// for *textual inputs* (incl textarea), normalize `onChange` -> `onInput`:
if (newProps.onchange && (type==='textarea' || (type.toLowerCase()==='input' && !/^fil|che|rad/i.test(props.type)))) {
let normalized = newProps.oninput || 'oninput';
Expand Down
7 changes: 7 additions & 0 deletions compat/test/browser/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ describe('preact-compat', () => {
expectToBeNormalized(<input {...props} type="text" />, '<input type="text">');

});

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

describe('Component', () => {
Expand Down

0 comments on commit 558fa70

Please sign in to comment.