Browse Source

fix(dialog): Don't steal focus

master
Hristo Terezov 5 years ago
parent
commit
3c1f056d2a
2 changed files with 44 additions and 0 deletions
  1. 30
    0
      react/features/base/util/react-focus-lock-wrapper.js
  2. 14
    0
      webpack.config.js

+ 30
- 0
react/features/base/util/react-focus-lock-wrapper.js View File

@@ -0,0 +1,30 @@
1
+// @flow
2
+import React from 'react';
3
+import FocusLock, { MoveFocusInside } from 'react-focus-lock';
4
+
5
+/**
6
+ * FocusLock wrapper that disable the FocusLock in the @atlaskit/modal-dialog. We need to disable it because if the
7
+ * iframe API is used and a dialog is displayed it is imposible to click on fields outside of the iframe (FocusLock
8
+ * will steal the focus from any element that is not part of the dialog).
9
+ */
10
+export default class FocusLockWrapper extends FocusLock<*> {
11
+    /**
12
+     * Implements React's {@link Component#render()}.
13
+     *
14
+     * @inheritdoc
15
+     * @returns {ReactElement}
16
+     */
17
+    render() {
18
+        const { children, ...otherProps } = this.props;
19
+
20
+        const props = {
21
+            ...otherProps,
22
+            disabled: true
23
+        };
24
+
25
+        // MoveFocusInside is added in order to initially bring the focus on the dialog.
26
+        return <FocusLock { ...props } ><MoveFocusInside>{children}</MoveFocusInside></FocusLock>;
27
+    }
28
+}
29
+
30
+export * from 'react-focus-lock';

+ 14
- 0
webpack.config.js View File

@@ -91,6 +91,20 @@ const config = {
91 91
                 'style-loader',
92 92
                 'css-loader'
93 93
             ]
94
+        }, {
95
+            test: /\/node_modules\/@atlaskit\/modal-dialog\/.*\.js$/,
96
+            resolve: {
97
+                alias: {
98
+                    'react-focus-lock': `${__dirname}/react/features/base/util/react-focus-lock-wrapper.js`
99
+                }
100
+            }
101
+        }, {
102
+            test: /\/react\/features\/base\/util\/react-focus-lock-wrapper.js$/,
103
+            resolve: {
104
+                alias: {
105
+                    'react-focus-lock': `${__dirname}/node_modules/react-focus-lock`
106
+                }
107
+            }
94 108
         } ]
95 109
     },
96 110
     node: {

Loading…
Cancel
Save