enables ctrl + enter for keypress event on browsers other than firefox (#10514)

* enables ctrl + enter for keypress event on browsers other than firefox

* makes comment more descriptive as to affected platforms

* reverting fiber results

* Reset changes to results.json

* Remove old test file

* Add tests in the right place
This commit is contained in:
Nicolas Straub
2018-01-05 16:31:25 +00:00
committed by Dan Abramov
parent 8d336aa97e
commit 43af41be53
2 changed files with 47 additions and 0 deletions
@@ -115,6 +115,47 @@ describe('SyntheticKeyboardEvent', () => {
);
expect(called).toBe(false);
});
it('when charCode is 10, returns 13', () => {
let charCode = null;
const node = ReactDOM.render(
<input
onKeyPress={e => {
charCode = e.charCode;
}}
/>,
container,
);
node.dispatchEvent(
new KeyboardEvent('keypress', {
charCode: 10,
bubbles: true,
cancelable: true,
}),
);
expect(charCode).toBe(13);
});
it('when charCode is 10 and ctrl is pressed, returns 13', () => {
let charCode = null;
const node = ReactDOM.render(
<input
onKeyPress={e => {
charCode = e.charCode;
}}
/>,
container,
);
node.dispatchEvent(
new KeyboardEvent('keypress', {
charCode: 10,
ctrlKey: true,
bubbles: true,
cancelable: true,
}),
);
expect(charCode).toBe(13);
});
});
// TODO: this seems IE8 specific.
+6
View File
@@ -31,6 +31,12 @@ function getEventCharCode(nativeEvent) {
charCode = keyCode;
}
// IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux)
// report Enter as charCode 10 when ctrl is pressed.
if (charCode === 10) {
charCode = 13;
}
// Some non-printable keys are reported in `charCode`/`keyCode`, discard them.
// Must not discard the (non-)printable Enter-key.
if (charCode >= 32 || charCode === 13) {