From bac2f5e2fcd763ddf637f1ac5fc6037d9dc0384a Mon Sep 17 00:00:00 2001 From: Alexandre Bourdin Date: Thu, 9 Apr 2026 16:21:31 +0200 Subject: [PATCH] Merge pull request #32641 from overleaf/ab-hide-add-comment-tooltip-on-blur MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [web] Hide add comment tooltip when clicking outside the editor GitOrigin-RevId: beff4c2e54fd28e47028f2bbc586f26fe6d3cc1d --- .../components/review-tooltip-menu.tsx | 21 ++++++++ .../review-panel/review-panel.spec.tsx | 49 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/services/web/frontend/js/features/review-panel/components/review-tooltip-menu.tsx b/services/web/frontend/js/features/review-panel/components/review-tooltip-menu.tsx index 0d792014cc..fdb9db9fb5 100644 --- a/services/web/frontend/js/features/review-panel/components/review-tooltip-menu.tsx +++ b/services/web/frontend/js/features/review-panel/components/review-tooltip-menu.tsx @@ -60,6 +60,27 @@ const ReviewTooltipMenu: FC = () => { } }, [tooltipState, previousTooltipState]) + useEffect(() => { + if (!show || !tooltipState || !permissions.comment) { + return + } + const handleMouseDown = (event: MouseEvent) => { + const target = event.target as Element | null + if ( + !view.contentDOM.contains(target) && + !target?.closest?.('.review-tooltip-menu-container') && + !target?.closest?.('.modal') && + !target?.closest?.('.modal-backdrop') + ) { + setShow(false) + } + } + document.addEventListener('mousedown', handleMouseDown) + return () => { + document.removeEventListener('mousedown', handleMouseDown) + } + }, [show, tooltipState, permissions.comment, view]) + const addComment = useCallback(() => { if (!permissions.comment) { return diff --git a/services/web/test/frontend/features/review-panel/review-panel.spec.tsx b/services/web/test/frontend/features/review-panel/review-panel.spec.tsx index 9a29df52da..9e3b00199a 100644 --- a/services/web/test/frontend/features/review-panel/review-panel.spec.tsx +++ b/services/web/test/frontend/features/review-panel/review-panel.spec.tsx @@ -538,6 +538,35 @@ describe('', function () { }) }) + describe('add comment tooltip visibility', function () { + beforeEach(function () { + cy.findByText('contentLine 12').type( + '{home}{shift}' + '{rightArrow}'.repeat(6), + { scrollBehavior: false } + ) + cy.get('.review-tooltip-menu').should('exist') + }) + + it('hides the tooltip when clicking a toolbar button', function () { + cy.findByRole('button', { name: 'Undo' }).click({ scrollBehavior: false }) + cy.get('.review-tooltip-menu').should('not.exist') + }) + + it('hides the tooltip when clicking outside the editor', function () { + cy.get('@review-panel').click({ scrollBehavior: false }) + cy.get('.review-tooltip-menu').should('not.exist') + }) + + it('keeps the add comment button functional when clicked', function () { + cy.get('.review-tooltip-add-comment-button').click({ + scrollBehavior: false, + }) + cy.get('@review-panel').within(() => { + cy.get('.review-panel-add-comment-textarea').should('exist') + }) + }) + }) + describe('bulk actions entry', function () { beforeEach(function () { // Select a deletion and an insertion @@ -590,6 +619,26 @@ describe('', function () { ]) }) }) + + it('keeps the tooltip visible when cancelling the accept confirmation modal', function () { + cy.get('@accept-selected-changes').click({ scrollBehavior: false }) + cy.findByRole('dialog').within(() => { + cy.findByRole('button', { name: 'Cancel' }).click({ + scrollBehavior: false, + }) + }) + cy.get('.review-tooltip-menu').should('exist') + }) + + it('keeps the tooltip visible when cancelling the reject confirmation modal', function () { + cy.get('@reject-selected-changes').click({ scrollBehavior: false }) + cy.findByRole('dialog').within(() => { + cy.findByRole('button', { name: 'Cancel' }).click({ + scrollBehavior: false, + }) + }) + cy.get('.review-tooltip-menu').should('exist') + }) }) describe('overview mode', function () {