Skip to content

Commit 69397d6

Browse files
nstraubManasJayanth
authored andcommitted
enables ctrl + enter for keypress event on browsers other than firefox (facebook#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
1 parent de9b3e1 commit 69397d6

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

packages/react-dom/src/events/__tests__/SyntheticKeyboardEvent-test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,47 @@ describe('SyntheticKeyboardEvent', () => {
115115
);
116116
expect(called).toBe(false);
117117
});
118+
119+
it('when charCode is 10, returns 13', () => {
120+
let charCode = null;
121+
const node = ReactDOM.render(
122+
<input
123+
onKeyPress={e => {
124+
charCode = e.charCode;
125+
}}
126+
/>,
127+
container,
128+
);
129+
node.dispatchEvent(
130+
new KeyboardEvent('keypress', {
131+
charCode: 10,
132+
bubbles: true,
133+
cancelable: true,
134+
}),
135+
);
136+
expect(charCode).toBe(13);
137+
});
138+
139+
it('when charCode is 10 and ctrl is pressed, returns 13', () => {
140+
let charCode = null;
141+
const node = ReactDOM.render(
142+
<input
143+
onKeyPress={e => {
144+
charCode = e.charCode;
145+
}}
146+
/>,
147+
container,
148+
);
149+
node.dispatchEvent(
150+
new KeyboardEvent('keypress', {
151+
charCode: 10,
152+
ctrlKey: true,
153+
bubbles: true,
154+
cancelable: true,
155+
}),
156+
);
157+
expect(charCode).toBe(13);
158+
});
118159
});
119160

120161
// TODO: this seems IE8 specific.

packages/react-dom/src/events/getEventCharCode.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ function getEventCharCode(nativeEvent) {
3131
charCode = keyCode;
3232
}
3333

34+
// IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux)
35+
// report Enter as charCode 10 when ctrl is pressed.
36+
if (charCode === 10) {
37+
charCode = 13;
38+
}
39+
3440
// Some non-printable keys are reported in `charCode`/`keyCode`, discard them.
3541
// Must not discard the (non-)printable Enter-key.
3642
if (charCode >= 32 || charCode === 13) {

0 commit comments

Comments
 (0)