diff --git a/js/ActionPopup/action-popup.js b/js/ActionPopup/action-popup.js index d5e86d2f..09fdca9d 100644 --- a/js/ActionPopup/action-popup.js +++ b/js/ActionPopup/action-popup.js @@ -50,6 +50,13 @@ const ActionModal = () => { }); }, []); + useEffect(() => { + document.addEventListener( 'click', exitModalOnOutsideClick ); + return () => { + document.removeEventListener( 'click', exitModalOnOutsideClick ); + }; + }, [isVisible] ); + const handleChange = (args) => { let id = args.index; delete args.index; @@ -179,14 +186,12 @@ const ActionModal = () => { }; // Close the popup when click on outside the modal. - document.body.addEventListener( 'click', function( e ) { - if ( isVisible ) { - if ( e.target.closest( '.popover-action-list' ) ) { - return; - } - toggleVisible(false); + const exitModalOnOutsideClick = ( e ) => { + if ( ! isVisible || ! e.target.closest( '.fz-action-popup' ) ) { + return; } - } ); + toggleVisible( false ); + }; // Click to open action popup. document.querySelectorAll( '[data-action_popup]' ).forEach( actionItem => { @@ -267,7 +272,7 @@ const ActionModal = () => {

{ __( 'If no action is needed, continue with using the original tag by clicking on the Save Actions button.', 'feedzy-rss-feeds' ) }

) } - + {action.length > 0 && ( )}
@@ -360,4 +365,4 @@ const ActionModal = () => { ReactDOM.render( , document.querySelector('#fz-action-popup') -); \ No newline at end of file +);