@@ -875,12 +875,7 @@ class ReactTextareaAutocomplete extends React.Component<
875875 }
876876 } ;
877877
878- _onClickAndBlurHandler = ( e : SyntheticFocusEvent < * > ) => {
879- const { onBlur } = this . props ;
880-
881- // If this is a click: e.target is the textarea, and e.relatedTarget is the thing
882- // that was actually clicked. If we clicked inside the autoselect dropdown, then
883- // that's not a blur, from the autoselect's point of view, so then do nothing.
878+ _shouldStayOpen = ( e : SyntheticFocusEvent < * > ) => {
884879 let el = e . relatedTarget ;
885880 // IE11 doesn't know about `relatedTarget` // https://stackoverflow.com/a/49325196/2719917
886881 if ( el === null ) {
@@ -892,15 +887,39 @@ class ReactTextareaAutocomplete extends React.Component<
892887 el instanceof Node &&
893888 this . dropdownRef . contains ( el )
894889 ) {
890+ return true ;
891+ }
892+
893+ return false ;
894+ } ;
895+
896+ _onClick = ( e : SyntheticFocusEvent < * > ) => {
897+ const { onClick } = this . props ;
898+
899+ if ( onClick ) {
900+ e . persist ( ) ;
901+ onClick ( e ) ;
902+ }
903+
904+ if ( this . _shouldStayOpen ( e ) ) {
895905 return;
896906 }
897907
898908 this . _closeAutocomplete ( ) ;
909+ } ;
910+
911+ _onBlur = ( e : SyntheticFocusEvent < * > ) => {
912+ const { onBlur } = this . props ;
899913
900914 if ( onBlur ) {
901915 e . persist ( ) ;
902916 onBlur ( e ) ;
903917 }
918+
919+ if ( this . _shouldStayOpen ( e ) ) {
920+ return;
921+ }
922+ this . _closeAutocomplete ( ) ;
904923 } ;
905924
906925 _onScrollHandler = ( ) => {
@@ -1012,9 +1031,9 @@ class ReactTextareaAutocomplete extends React.Component<
10121031 onScroll = { this . _onScrollHandler }
10131032 onClick = {
10141033 // The textarea itself is outside the autoselect dropdown.
1015- this . _onClickAndBlurHandler
1034+ this . _onClick
10161035 }
1017- onBlur = { this . _onClickAndBlurHandler }
1036+ onBlur = { this . _onBlur }
10181037 value = { value }
10191038 style = { style }
10201039 { ...extraAttrs }
@@ -1135,6 +1154,7 @@ ReactTextareaAutocomplete.propTypes = {
11351154 onChange : PropTypes . func ,
11361155 onSelect : PropTypes . func ,
11371156 onBlur : PropTypes . func ,
1157+ onClick : PropTypes . func ,
11381158 textAreaComponent : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . object ] ) ,
11391159 movePopupAsYouType : PropTypes . bool ,
11401160 onCaretPositionChange : PropTypes . func ,
0 commit comments