-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
List View: Try scrolling selected blocks into view when single block …
…selection changes
- Loading branch information
1 parent
d9f13a8
commit c812bba
Showing
3 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/block-editor/src/components/list-view/use-list-view-scroll-into-view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEffect } from '@wordpress/element'; | ||
|
||
export default function useListViewScrollIntoView( { | ||
firstSelectedBlockClientId, | ||
numBlocksSelected, | ||
selectedItemRef, | ||
} ) { | ||
useEffect( () => { | ||
if ( | ||
numBlocksSelected !== 1 || | ||
! selectedItemRef?.current || | ||
! selectedItemRef.current.scrollIntoView | ||
) { | ||
return; | ||
} | ||
|
||
const { top, height } = selectedItemRef.current.getBoundingClientRect(); | ||
const { innerHeight } = window; | ||
|
||
// If the selected block is not visible, scroll to it. | ||
// The hard-coded value of 110 corresponds to the position at the top of the scrollable area. | ||
if ( top < 110 || top + height > innerHeight ) { | ||
selectedItemRef.current.scrollIntoView(); | ||
} | ||
}, [ | ||
firstSelectedBlockClientId, | ||
numBlocksSelected, | ||
selectedItemRef?.current, | ||
] ); | ||
} |
c812bba
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.
Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3844502211
📝 Reported issues:
specs/editor/various/multi-block-selection.test.js