File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
x-pack/solutions/search/plugins/enterprise_search/public/applications/enterprise_search_content/components/connector_detail/components Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 5
5
* 2.0.
6
6
*/
7
7
8
- import React , { useState } from 'react' ;
8
+ import React , { useRef , useState } from 'react' ;
9
+
10
+ import { defer } from 'lodash' ;
9
11
10
12
import {
11
13
EuiButtonIcon ,
@@ -83,18 +85,32 @@ export const GeneratedConfigFields: React.FC<GeneratedConfigFieldsProps> = ({
83
85
generateApiKey,
84
86
isGenerateLoading,
85
87
} ) => {
88
+ const apiKeyContainerRef = useRef < HTMLDivElement > ( null ) ;
89
+ const restoreFocusRef = useRef < HTMLElement | null > ( null ) ;
86
90
const [ isModalVisible , setIsModalVisible ] = useState ( false ) ;
87
91
88
92
const refreshButtonClick = ( ) => {
93
+ restoreFocusRef . current = document . activeElement as HTMLElement ;
89
94
setIsModalVisible ( true ) ;
90
95
} ;
96
+ const restoreFocus = ( ) => {
97
+ if ( ! restoreFocusRef . current || ( restoreFocusRef . current as HTMLButtonElement ) . disabled ) {
98
+ apiKeyContainerRef . current ?. focus ( ) ;
99
+ return ;
100
+ } else {
101
+ restoreFocusRef . current ?. focus ( ) ;
102
+ }
103
+ restoreFocusRef . current = null ;
104
+ } ;
105
+
91
106
const onCancel = ( ) => {
92
107
setIsModalVisible ( false ) ;
93
108
} ;
94
109
95
110
const onConfirm = ( ) => {
96
111
if ( generateApiKey ) generateApiKey ( ) ;
97
112
setIsModalVisible ( false ) ;
113
+ defer ( restoreFocus ) ;
98
114
} ;
99
115
100
116
return (
@@ -223,6 +239,8 @@ export const GeneratedConfigFields: React.FC<GeneratedConfigFieldsProps> = ({
223
239
gutterSize = "xs"
224
240
justifyContent = "flexEnd"
225
241
alignItems = "center"
242
+ ref = { apiKeyContainerRef }
243
+ tabIndex = { - 1 }
226
244
>
227
245
{ apiKey ?. encoded ? (
228
246
< EuiFlexItem >
You can’t perform that action at this time.
0 commit comments