@@ -14,12 +14,20 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- import React , { InputHTMLAttributes , SelectHTMLAttributes , TextareaHTMLAttributes , RefObject , createRef } from "react" ;
17
+ import React , {
18
+ InputHTMLAttributes ,
19
+ SelectHTMLAttributes ,
20
+ TextareaHTMLAttributes ,
21
+ RefObject ,
22
+ createRef ,
23
+ KeyboardEvent ,
24
+ } from "react" ;
18
25
import classNames from "classnames" ;
19
26
import { debounce } from "lodash" ;
20
27
21
28
import { IFieldState , IValidationResult } from "./Validation" ;
22
29
import Tooltip from "./Tooltip" ;
30
+ import { Key } from "../../../Keyboard" ;
23
31
24
32
// Invoke validation from user input (when typing, etc.) at most once every N ms.
25
33
const VALIDATION_THROTTLE_MS = 200 ;
@@ -232,6 +240,18 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
232
240
return this . props . inputRef ?? this . _inputRef ;
233
241
}
234
242
243
+ private onKeyDown = ( evt : KeyboardEvent < HTMLDivElement > ) : void => {
244
+ // If the tooltip is displayed to show a feedback and Escape is pressed
245
+ // The tooltip is hided
246
+ if ( this . state . feedbackVisible && evt . key === Key . ESCAPE ) {
247
+ evt . preventDefault ( ) ;
248
+ evt . stopPropagation ( ) ;
249
+ this . setState ( {
250
+ feedbackVisible : false ,
251
+ } ) ;
252
+ }
253
+ } ;
254
+
235
255
public render ( ) : React . ReactNode {
236
256
/* eslint @typescript-eslint/no-unused-vars: ["error", { "ignoreRestSiblings": true }] */
237
257
const {
@@ -318,7 +338,7 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
318
338
} ) ;
319
339
320
340
return (
321
- < div className = { fieldClasses } >
341
+ < div className = { fieldClasses } onKeyDown = { this . onKeyDown } >
322
342
{ prefixContainer }
323
343
{ fieldInput }
324
344
< label htmlFor = { this . id } > { this . props . label } </ label >
0 commit comments