mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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:
committed by
Dan Abramov
parent
8d336aa97e
commit
43af41be53
@@ -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.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user