getEventCharCode.js — react Source File
Architecture documentation for getEventCharCode.js, a javascript file in the react codebase. 0 imports, 2 dependents.
Entity Profile
Dependency Diagram
graph LR d78b8333_1674_238a_05bc_00693b9f27d2["getEventCharCode.js"] 9c3d71d9_41af_c5e7_cd35_d25bbf6cf606["SyntheticEvent.js"] 9c3d71d9_41af_c5e7_cd35_d25bbf6cf606 --> d78b8333_1674_238a_05bc_00693b9f27d2 43bccccc_6fb9_1e3f_9c97_ea90d6d01475["SimpleEventPlugin.js"] 43bccccc_6fb9_1e3f_9c97_ea90d6d01475 --> d78b8333_1674_238a_05bc_00693b9f27d2 style d78b8333_1674_238a_05bc_00693b9f27d2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
/**
* `charCode` represents the actual "character code" and is safe to use with
* `String.fromCharCode`. As such, only keys that correspond to printable
* characters produce a valid `charCode`, the only exception to this is Enter.
* The Tab-key is considered non-printable and does not have a `charCode`,
* presumably because it does not produce a tab-character in browsers.
*
* @param {object} nativeEvent Native browser event.
* @return {number} Normalized `charCode` property.
*/
function getEventCharCode(nativeEvent: KeyboardEvent): number {
let charCode;
const keyCode = nativeEvent.keyCode;
if ('charCode' in nativeEvent) {
charCode = nativeEvent.charCode;
// FF does not set `charCode` for the Enter-key, check against `keyCode`.
if (charCode === 0 && keyCode === 13) {
charCode = 13;
}
} else {
// IE8 does not implement `charCode`, but `keyCode` has the correct value.
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) {
return charCode;
}
return 0;
}
export default getEventCharCode;
Domain
Subdomains
Functions
Imported By
Source
Frequently Asked Questions
What does getEventCharCode.js do?
getEventCharCode.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in getEventCharCode.js?
getEventCharCode.js defines 1 function(s): getEventCharCode.
What files import getEventCharCode.js?
getEventCharCode.js is imported by 2 file(s): SimpleEventPlugin.js, SyntheticEvent.js.
Where is getEventCharCode.js in the architecture?
getEventCharCode.js is located at packages/react-dom-bindings/src/events/getEventCharCode.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-dom-bindings/src/events).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free