Skip to content

Commit

Permalink
animate scrolling if reduced motion is off
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu committed May 8, 2024
1 parent 8543cfd commit e20cff2
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/**
* WordPress dependencies
*/
import { useRefEffect } from '@wordpress/compose';
import { useReducedMotion, useRefEffect } from '@wordpress/compose';

export function useScrollIntoView( { isSelected } ) {
const prefersReducedMotion = useReducedMotion();
return useRefEffect(
( node ) => {
if ( isSelected ) {
Expand All @@ -17,7 +18,11 @@ export function useScrollIntoView( { isSelected } ) {
// Once observing starts, we always get an initial
// entry with the intersecting state.
if ( ! entries[ 0 ].isIntersecting ) {
node.scrollIntoView();
node.scrollIntoView( {
behavior: prefersReducedMotion
? 'instant'
: 'smooth',
} );
observer.disconnect();
}
}
Expand Down

0 comments on commit e20cff2

Please sign in to comment.