Skip to content

Conversation

@karthick-murugan
Copy link
Contributor

@karthick-murugan karthick-murugan commented Nov 10, 2025

What?

Closes #72858

This PR fixes the focus state issue where individual notes and their corresponding blocks were not properly collapsing when focus moved away or when clicking outside the note. The fix ensures that expanded notes automatically collapse when:

  1. Focus moves away from the note thread
  2. The user interacts with elements outside the note

Why?

Previously, when a note was expanded and the user clicked outside the note (either within the panel or outside it), or when focus moved away from the note, the note's focus state (drop shadow, white background, etc.) and the corresponding block highlighting would persist incorrectly. This created a confusing user experience where notes appeared to remain selected even after the user had moved on.

This issue was reported in #72858 and affects the Notes feature in the Gutenberg editor, particularly when using the collaborative sidebar.

How?

The implementation adds two key behaviors:

  1. Focus-based collapse: Enhanced the onBlur handler in the Thread component to detect when focus moves outside the thread element and automatically collapse the note by calling unselectThread().

  2. Selection clearing mechanism: Added a clearSelection callback function in the Comments component that:

    • Finds the currently selected thread
    • Clears its block spotlight
    • Resets the selected thread state
    • Closes any open new note forms

Testing Instructions

  1. Open a post or page in the editor.
  2. Add a few blocks with notes (or create notes on existing blocks).
  3. Click on a note to expand it - verify it expands and the block is highlighted.
  4. Test clicking outside the note:
    • Click on empty space within the notes panel - the note should collapse and block highlighting should be removed.
    • Click on another note - the previous note should collapse and the new one should expand.
  5. Test focus behavior:
    • Click on a note to expand it.
    • Click outside the note or tab away - the note should automatically collapse.
    • Verify that the block spotlight is removed when the note collapses.

Video

REC-20251110143032.mp4

@karthick-murugan karthick-murugan marked this pull request as ready for review November 10, 2025 09:15
@github-actions
Copy link

github-actions bot commented Nov 10, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: karthick-murugan <karthickmurugan@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: desrosj <desrosj@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Feature] Notes Phase 3 of the Gutenberg roadmap around block commenting labels Nov 10, 2025
@github-project-automation github-project-automation bot moved this to 🔎 Needs Review in WordPress 6.9 Editor Tasks Nov 10, 2025
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

I believe the failing tests are related to this pull request. Could you investigate the cause?

@jeffpaul
Copy link
Member

@karthick-murugan FYI there's a merge conflict if you would please review/resolve as well

@karthick-murugan
Copy link
Contributor Author

Thanks for the PR!

I believe the failing tests are related to this pull request. Could you investigate the cause?

I’m seeing consistent e2e test failures in block-comments.spec.js — specifically expect(locator).toBeFocused() after clicking the “x more replies” button.

The issue seems to be that the new inline onBlur handler in comments.js immediately collapses/unselects a thread when focus leaves the thread element. During the “x more replies” click, a focus/blur sequence fires, triggering the collapse logic before focus can be restored — causing the test to fail. Therefore clicking on x more replies the focus of thread is lost.

Please provide some ideas to fix this issue.

@ellatrix
Copy link
Member

If relevant, let's add the backport label as soon as possible so this gets more eyes

@t-hamano
Copy link
Contributor

I see, this is a bit complicated. The note loses focus in various situations, but as I understand it, we only need to collapse the note when we perform the following two actions:

  • The focus was lost during tab key navigation.
  • clicked outside the note with the mouse.

The note should not be collapsed during any operations other than those mentioned.

I am currently considering the best approach...

cc @adamsilverstein @Mamaduka

@t-hamano
Copy link
Contributor

@karthick-murugan, I was testing it in a separate pull request, and it seems to be working correctly: #73158

@t-hamano
Copy link
Contributor

@karthick-murugan, I'd like to close this PR in favor of #73158, but thank you for your work!

@t-hamano t-hamano closed this Nov 11, 2025
@github-project-automation github-project-automation bot moved this from 🔎 Needs Review to ✅ Done in WordPress 6.9 Editor Tasks Nov 11, 2025
@karthick-murugan karthick-murugan deleted the individual-notes-focus-state branch November 12, 2025 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Notes Phase 3 of the Gutenberg roadmap around block commenting [Type] Bug An existing feature does not function as intended

Projects

Development

Successfully merging this pull request may close these issues.

Focus state for individual notes or a note's block is not removed as expected

4 participants