-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Notes: Keep tall floating threads scrollable on short content #77821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,11 @@ import { Note } from './note'; | |
| import { NoteCard } from './note-card'; | ||
| import { NoteForm } from './note-form'; | ||
| import { FloatingContainer } from './floating-container'; | ||
| import { focusNoteThread, getNoteExcerpt } from './utils'; | ||
| import { | ||
| focusNoteThread, | ||
| getNoteExcerpt, | ||
| scrollNoteThreadIntoView, | ||
| } from './utils'; | ||
| import { store as editorStore } from '../../store'; | ||
| import { unlock } from '../../lock-unlock'; | ||
|
|
||
|
|
@@ -68,6 +72,15 @@ export function NoteThread( { | |
| return () => unregisterThread?.( note.id ); | ||
| }, [ relatedBlockElement, note.id, registerThread, unregisterThread ] ); | ||
|
|
||
| // Scroll the thread into view when it becomes selected, and re-scroll | ||
| // when its floating position settles after `useFloatingBoard` recomputes. | ||
| useEffect( () => { | ||
| if ( ! isSelected || note.id === 'new' ) { | ||
| return; | ||
| } | ||
| scrollNoteThreadIntoView( note.id, sidebarRef.current ); | ||
| }, [ isSelected, floating?.y, note.id, sidebarRef ] ); | ||
|
|
||
| const onMouseEnter = () => { | ||
| debouncedToggleBlockHighlight( note.blockClientId, true ); | ||
| }; | ||
|
|
@@ -113,26 +126,31 @@ export function NoteThread( { | |
| // - An element other than a note is clicked. | ||
| // - Focus was lost by tabbing. | ||
| toggleBlockHighlight( note.blockClientId, false ); | ||
| unselectNote(); | ||
| onDeselectNote(); | ||
| }; | ||
|
|
||
| const handleNoteSelect = () => { | ||
| const onSelectNote = () => { | ||
| if ( isSelected ) { | ||
| return; | ||
| } | ||
|
|
||
| selectNote( note.id ); | ||
| focusNoteThread( note.id, sidebarRef.current ); | ||
| toggleBlockSpotlight( note.blockClientId, true ); | ||
| if ( !! note.blockClientId ) { | ||
| // Pass `null` as the second parameter to prevent focusing the block. | ||
| selectBlock( note.blockClientId, null ); | ||
| } | ||
| }; | ||
|
|
||
| const unselectNote = () => { | ||
| const onDeselectNote = () => { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Trying to match naming patterns. |
||
| selectNote( undefined ); | ||
| toggleBlockSpotlight( note.blockClientId, false ); | ||
| }; | ||
|
|
||
| const handleResolve = () => { | ||
| onEditNote( { id: note.id, status: 'approved' } ); | ||
| unselectNote(); | ||
| onDeselectNote(); | ||
| if ( isFloating ) { | ||
| relatedBlockElement?.focus(); | ||
| } else { | ||
|
|
@@ -181,7 +199,7 @@ export function NoteThread( { | |
| } ) } | ||
| id={ `note-thread-${ note.id }` } | ||
| gap="md" | ||
| onClick={ handleNoteSelect } | ||
| onClick={ onSelectNote } | ||
| onMouseEnter={ onMouseEnter } | ||
| onMouseLeave={ onMouseLeave } | ||
| onFocus={ onFocus } | ||
|
|
@@ -247,9 +265,9 @@ export function NoteThread( { | |
| size="compact" | ||
| variant="tertiary" | ||
| className="editor-collab-sidebar-panel__more-reply-button" | ||
| onClick={ () => { | ||
| selectNote( note.id ); | ||
| focusNoteThread( note.id, sidebarRef.current ); | ||
| onClick={ ( event ) => { | ||
| event.stopPropagation(); | ||
| onSelectNote(); | ||
| } } | ||
| > | ||
| { sprintf( | ||
|
|
@@ -295,7 +313,7 @@ export function NoteThread( { | |
| onCancel={ ( event ) => { | ||
| // Prevent the parent onClick from being triggered. | ||
| event.stopPropagation(); | ||
| unselectNote(); | ||
| onDeselectNote(); | ||
| focusNoteThread( note.id, sidebarRef.current ); | ||
| } } | ||
| labels={ { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,12 +111,15 @@ export function Notes( { notes, sidebarRef, isFloating = false, styles } ) { | |
| return; | ||
| } | ||
|
|
||
| if ( nextThread ) { | ||
| selectNote( nextThread.id ); | ||
| focusNoteThread( nextThread.id, sidebarRef.current ); | ||
| } else if ( prevThread ) { | ||
| selectNote( prevThread.id ); | ||
| focusNoteThread( prevThread.id, sidebarRef.current ); | ||
| const adjacentThread = nextThread ?? prevThread; | ||
| if ( adjacentThread ) { | ||
| selectNote( adjacentThread.id ); | ||
| focusNoteThread( adjacentThread.id, sidebarRef.current ); | ||
| if ( adjacentThread.blockClientId ) { | ||
| toggleBlockSpotlight( adjacentThread.blockClientId, true ); | ||
| // Pass `null` as the second parameter to prevent focusing the block. | ||
| selectBlock( adjacentThread.blockClientId, null ); | ||
| } | ||
|
Comment on lines
+118
to
+122
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fully related to this issue. Canvas syncing was missing, causing stale block selection/spotlight. This matches keyboard nav behavior. |
||
| } else { | ||
| selectNote( undefined ); | ||
| toggleBlockSpotlight( note.blockClientId, false ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A single method to handle selection for the thread body or show more reply clicks.