Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/components/AutoCompleteTextarea/Textarea.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {

import { CommandItem } from '../CommandItem';
import { UserItem } from '../UserItem';
import { isSafari } from '../../utils/browsers';

export class ReactTextareaAutocomplete extends React.Component {
static defaultProps = {
Expand Down Expand Up @@ -565,7 +566,16 @@ export class ReactTextareaAutocomplete extends React.Component {
// that was actually clicked. If we clicked inside the auto-select dropdown, then
// that's not a blur, from the auto-select point of view, so then do nothing.
const el = e.relatedTarget;
if (this.dropdownRef && el instanceof Node && this.dropdownRef.contains(el)) {
// If this is a blur event in Safari, then relatedTarget is never a dropdown item, but a common parent
// of textarea and dropdown container. That means that dropdownRef will not contain its parent and the
// autocomplete will be closed before onclick handler can be invoked selecting an item.
// It seems that Safari has different implementation determining the relatedTarget node than Chrome and Firefox.
// Therefore, if focused away in Safari, the dropdown will be kept rendered until pressing Esc or selecting and item from it.
const focusedAwayInSafari = isSafari() && e.type === 'blur';
if (
(this.dropdownRef && el instanceof Node && this.dropdownRef.contains(el)) ||
focusedAwayInSafari
) {
return;
}

Expand Down
4 changes: 4 additions & 0 deletions src/utils/browsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const isSafari = () => {
if (typeof navigator === 'undefined') return false;
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent || '');
};