@samitouri / QOS-React / commits / 43af41be53

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

Nicolas Straub committed Jan 5, 2018 at 13:31 UTC 43af41be537da5a802c2d0c767df3e406f4a81cc
2 files changed +47
packages/react-dom/src/events/__tests__/SyntheticKeyboardEvent-test.js
+41
@@ -115,6 +115,47 @@ describe('SyntheticKeyboardEvent', () => {
115 );
116 expect(called).toBe(false);
117 });
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 + });
159 });
160
161 // TODO: this seems IE8 specific.
packages/react-dom/src/events/getEventCharCode.js
+6
@@ -31,6 +31,12 @@ function getEventCharCode(nativeEvent) {
31 charCode = keyCode;
32 }
33
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 +
40 // Some non-printable keys are reported in `charCode`/`keyCode`, discard them.
41 // Must not discard the (non-)printable Enter-key.
42 if (charCode >= 32 || charCode === 13) {