From 79b9408f1fc7c2f68abd83d70727b6b27f0f25f2 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 14 Nov 2019 15:54:50 -0800 Subject: [PATCH] Message: Only focus if focus is not inside container already --- ts/components/conversation/InlineNotificationWrapper.tsx | 6 ++++-- ts/components/conversation/Message.tsx | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ts/components/conversation/InlineNotificationWrapper.tsx b/ts/components/conversation/InlineNotificationWrapper.tsx index 3f7513f167..babace2fbc 100644 --- a/ts/components/conversation/InlineNotificationWrapper.tsx +++ b/ts/components/conversation/InlineNotificationWrapper.tsx @@ -11,8 +11,10 @@ export class InlineNotificationWrapper extends React.Component { public focusRef: React.RefObject = React.createRef(); public setFocus = () => { - if (this.focusRef.current) { - this.focusRef.current.focus(); + const container = this.focusRef.current; + + if (container && !container.contains(document.activeElement)) { + container.focus(); } }; diff --git a/ts/components/conversation/Message.tsx b/ts/components/conversation/Message.tsx index 4a75220e04..eeb95661c1 100644 --- a/ts/components/conversation/Message.tsx +++ b/ts/components/conversation/Message.tsx @@ -187,8 +187,10 @@ export class Message extends React.PureComponent { }; public setFocus = () => { - if (this.focusRef.current) { - this.focusRef.current.focus(); + const container = this.focusRef.current; + + if (container && !container.contains(document.activeElement)) { + container.focus(); } };