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
This commit is contained in:
Simon Backx 2022-08-10 15:41:57 +02:00
parent 1640901114
commit b703ddd703

View File

@ -258,7 +258,19 @@ const Form = (props) => {
return; 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(); editor?.commands.focus();
window.scrollTo({ window.scrollTo({
top: getScrollToPosition(), top: getScrollToPosition(),