Add flow types in getEventModifierState (#13909)
Abdul Rauf committed
Oct 21, 2018 at 23:20 UTC
663835a43a5a92ff63c3e3b43e4c9ff40dde173b
1 file changed
+8
-2
packages/react-dom/src/events/getEventModifierState.js
+8
-2
@@ -3,6 +3,8 @@
3
*
4
* This source code is licensed under the MIT license found in the
5
* LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow
8
*/
9
10
/**
@@ -10,6 +12,8 @@
12
* @see http://www.w3.org/TR/DOM-Level-3-Events/#keys-Modifiers
13
*/
14
15
+import type {AnyNativeEvent} from 'events/PluginModuleType';
16
+
17
const modifierKeyToProp = {
18
Alt: 'altKey',
19
Control: 'ctrlKey',
@@ -20,7 +24,7 @@ const modifierKeyToProp = {
24
// IE8 does not implement getModifierState so we simply map it to the only
25
// modifier keys exposed by the event itself, does not support Lock-keys.
26
// Currently, all major browsers except Chrome seems to support Lock-keys.
23
-function modifierStateGetter(keyArg) {
27
+function modifierStateGetter(keyArg: string): boolean {
28
const syntheticEvent = this;
29
const nativeEvent = syntheticEvent.nativeEvent;
30
if (nativeEvent.getModifierState) {
@@ -30,7 +34,9 @@ function modifierStateGetter(keyArg) {
34
return keyProp ? !!nativeEvent[keyProp] : false;
35
}
36
33
-function getEventModifierState(nativeEvent) {
37
+function getEventModifierState(
38
+ nativeEvent: AnyNativeEvent,
39
+): (keyArg: string) => boolean {
40
return modifierStateGetter;
41
}
42