mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Fixed closing context menus when clicking outside them
fixes https://github.com/TryGhost/Team/issues/1702
This commit is contained in:
parent
20f2b26c23
commit
b262d7010a
2 changed files with 32 additions and 5 deletions
|
@ -165,8 +165,6 @@ const Form = (props) => {
|
||||||
const isFocused = editor?.isFocused || !editor?.isEmpty;
|
const isFocused = editor?.isFocused || !editor?.isEmpty;
|
||||||
|
|
||||||
const focusEditor = (event) => {
|
const focusEditor = (event) => {
|
||||||
event.stopPropagation();
|
|
||||||
|
|
||||||
if (memberName) {
|
if (memberName) {
|
||||||
editor.commands.focus();
|
editor.commands.focus();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, {useContext} from 'react';
|
import React, {useContext, useEffect, useRef} from 'react';
|
||||||
import AppContext from '../../AppContext';
|
import AppContext from '../../AppContext';
|
||||||
import AdminContextMenu from './AdminContextMenu';
|
import AdminContextMenu from './AdminContextMenu';
|
||||||
import AuthorContextMenu from './AuthorContextMenu';
|
import AuthorContextMenu from './AuthorContextMenu';
|
||||||
|
@ -9,6 +9,33 @@ const CommentContextMenu = (props) => {
|
||||||
const comment = props.comment;
|
const comment = props.comment;
|
||||||
const isAuthor = member && comment.member?.uuid === member?.uuid;
|
const isAuthor = member && comment.member?.uuid === member?.uuid;
|
||||||
const isAdmin = !!admin;
|
const isAdmin = !!admin;
|
||||||
|
const element = useRef();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const listener = () => {
|
||||||
|
props.close();
|
||||||
|
};
|
||||||
|
|
||||||
|
// We need to listen for the window outside the iframe, and also the iframe window events
|
||||||
|
window.addEventListener('click', listener, {passive: true});
|
||||||
|
const el = element.current?.ownerDocument?.defaultView;
|
||||||
|
|
||||||
|
if (el && el !== window) {
|
||||||
|
el.addEventListener('click', listener, {passive: true});
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('click', listener, {passive: true});
|
||||||
|
if (el && el !== window) {
|
||||||
|
el.removeEventListener('click', listener, {passive: true});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [props]);
|
||||||
|
|
||||||
|
// Prevent closing the context menu when clicking inside of it
|
||||||
|
const stopPropagation = (event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
};
|
||||||
|
|
||||||
let contextMenu = null;
|
let contextMenu = null;
|
||||||
if (comment.status === 'published') {
|
if (comment.status === 'published') {
|
||||||
|
@ -30,8 +57,10 @@ const CommentContextMenu = (props) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-w-[170px] bg-white absolute font-sans rounded py-3 px-4 shadow-lg text-sm whitespace-nowrap z-10 dark:bg-zinc-900 dark:text-white outline-0">
|
<div ref={element} onClick={stopPropagation}>
|
||||||
{contextMenu}
|
<div className="min-w-[170px] bg-white absolute font-sans rounded py-3 px-4 shadow-lg text-sm whitespace-nowrap z-10 dark:bg-zinc-900 dark:text-white outline-0">
|
||||||
|
{contextMenu}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue