Skip to content

Commit 76626fd

Browse files
authored
Merge pull request #2016 from GetStream/develop
v10.8.1
2 parents 3273b8c + 9100908 commit 76626fd

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/components/AutoCompleteTextarea/Textarea.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515

1616
import { CommandItem } from '../CommandItem';
1717
import { UserItem } from '../UserItem';
18+
import { isSafari } from '../../utils/browsers';
1819

1920
export 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

src/utils/browsers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const isSafari = () => {
2+
if (typeof navigator === 'undefined') return false;
3+
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent || '');
4+
};

0 commit comments

Comments
 (0)