File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
components/AutoCompleteTextarea Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {
1515
1616import { CommandItem } from '../CommandItem' ;
1717import { UserItem } from '../UserItem' ;
18+ import { isSafari } from '../../utils/browsers' ;
1819
1920export class ReactTextareaAutocomplete extends React . Component {
2021 static defaultProps = {
@@ -565,7 +566,16 @@ export class ReactTextareaAutocomplete extends React.Component {
565566 // that was actually clicked. If we clicked inside the auto-select dropdown, then
566567 // that's not a blur, from the auto-select point of view, so then do nothing.
567568 const el = e . relatedTarget ;
568- if ( this . dropdownRef && el instanceof Node && this . dropdownRef . contains ( el ) ) {
569+ // If this is a blur event in Safari, then relatedTarget is never a dropdown item, but a common parent
570+ // of textarea and dropdown container. That means that dropdownRef will not contain its parent and the
571+ // autocomplete will be closed before onclick handler can be invoked selecting an item.
572+ // It seems that Safari has different implementation determining the relatedTarget node than Chrome and Firefox.
573+ // Therefore, if focused away in Safari, the dropdown will be kept rendered until pressing Esc or selecting and item from it.
574+ const focusedAwayInSafari = isSafari ( ) && e . type === 'blur' ;
575+ if (
576+ ( this . dropdownRef && el instanceof Node && this . dropdownRef . contains ( el ) ) ||
577+ focusedAwayInSafari
578+ ) {
569579 return ;
570580 }
571581
Original file line number Diff line number Diff line change 1+ export const isSafari = ( ) => {
2+ if ( typeof navigator === 'undefined' ) return false ;
3+ return / ^ ( (? ! c h r o m e | a n d r o i d ) .) * s a f a r i / i. test ( navigator . userAgent || '' ) ;
4+ } ;
You can’t perform that action at this time.
0 commit comments