From b703ddd70377208d68f7ab51752ebde179a88942 Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Wed, 10 Aug 2022 15:41:57 +0200 Subject: [PATCH] Fixed C keyboard shortcut when input is focused fixes https://github.com/TryGhost/Team/issues/1767 - Only focus the form if there is no other input focused on the page --- apps/comments-ui/src/components/Form.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/comments-ui/src/components/Form.js b/apps/comments-ui/src/components/Form.js index 8421dcbf5a..9cbafbd269 100644 --- a/apps/comments-ui/src/components/Form.js +++ b/apps/comments-ui/src/components/Form.js @@ -258,7 +258,19 @@ const Form = (props) => { return; } - if (event.key === 'c' && !props.isEdit && !props.isReply && !editor?.isFocused) { + let focusedElement = document.activeElement; + while (focusedElement && focusedElement.tagName === 'IFRAME') { + if (!focusedElement.contentDocument) { + // CORS issue + // disable the C shortcut when we have a focused external iframe + break; + } + + focusedElement = focusedElement.contentDocument.activeElement; + } + const hasInputFocused = focusedElement && (focusedElement.tagName === 'INPUT' || focusedElement.tagName === 'TEXTAREA' || focusedElement.tagName === 'IFRAME' || focusedElement.contentEditable === 'true'); + + if (event.key === 'c' && !props.isEdit && !props.isReply && !editor?.isFocused && !hasInputFocused) { editor?.commands.focus(); window.scrollTo({ top: getScrollToPosition(),