Block Comments: Avoid focus loss after creating a comment#72139
Block Comments: Avoid focus loss after creating a comment#72139
Conversation
|
Size Change: +114 B (+0.01%) Total Size: 1.96 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in e73c8d4. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18333314368
|
|
After a new comment is created, the comment thread will be in a "selected" state. Perhaps when a comment is opened (selected), That is, make the following changes to trunk: diff --git a/packages/editor/src/components/collab-sidebar/comments.js b/packages/editor/src/components/collab-sidebar/comments.js
index 1434cdae12..e5a3c732f5 100644
--- a/packages/editor/src/components/collab-sidebar/comments.js
+++ b/packages/editor/src/components/collab-sidebar/comments.js
@@ -124,6 +124,12 @@ function Thread( {
50
);
+ useEffect( () => {
+ if ( isSelected ) {
+ focusCommentThread( thread.id, commentSidebarRef.current );
+ }
+ }, [ isSelected, thread.id, commentSidebarRef ] );
+
const onMouseEnter = () => {
debouncedToggleBlockHighlight( thread.blockClientId, true );
}; |
|
In my experience, similar effects break easily. The Another option I'm considering is using |
e893221 to
e73c8d4
Compare
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| await blockCommentUtils.addBlockWithComment( { | ||
| type: 'core/paragraph', |
There was a problem hiding this comment.
The addBlockWithComment also clears out snackbars, which steals the focus. Had to inline the comment creation logic.
| // Stop trying after 3 seconds. | ||
| timer = setTimeout( () => { | ||
| observer.disconnect(); | ||
| resolve( null ); | ||
| }, 3000 ); |
There was a problem hiding this comment.
Not sure if we want to make this configurable. I guess it will work as a default value for now.
…72139) Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: roseg43 <gabertronic@git.wordpress.org> Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>
What?
Closes #71677.
Related #72024.
PR ensures the focus is moved to the newly created comment. I've also adjusted e2e tests to assert for focus.
Why?
When a new comment is created, focus is lost or returns to the page body, rather than remaining on the newly created comment.
Testing Instructions
Testing Instructions for Keyboard
Same.