@@ -14,12 +14,20 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
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" ;
1825import classNames from "classnames" ;
1926import { debounce } from "lodash" ;
2027
2128import { IFieldState , IValidationResult } from "./Validation" ;
2229import Tooltip from "./Tooltip" ;
30+ import { Key } from "../../../Keyboard" ;
2331
2432// Invoke validation from user input (when typing, etc.) at most once every N ms.
2533const VALIDATION_THROTTLE_MS = 200 ;
@@ -232,6 +240,18 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
232240 return this . props . inputRef ?? this . _inputRef ;
233241 }
234242
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+
235255 public render ( ) : React . ReactNode {
236256 /* eslint @typescript-eslint/no-unused-vars: ["error", { "ignoreRestSiblings": true }] */
237257 const {
@@ -318,7 +338,7 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
318338 } ) ;
319339
320340 return (
321- < div className = { fieldClasses } >
341+ < div className = { fieldClasses } onKeyDown = { this . onKeyDown } >
322342 { prefixContainer }
323343 { fieldInput }
324344 < label htmlFor = { this . id } > { this . props . label } </ label >
0 commit comments