From e20cff22afc49fac5bf7a2009d3451693af09ab2 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Wed, 8 May 2024 10:45:57 +0900 Subject: [PATCH] animate scrolling if reduced motion is off --- .../block-list/use-block-props/use-scroll-into-view.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/components/block-list/use-block-props/use-scroll-into-view.js b/packages/block-editor/src/components/block-list/use-block-props/use-scroll-into-view.js index 32007970d5bd7..ec210bc6f2eb9 100644 --- a/packages/block-editor/src/components/block-list/use-block-props/use-scroll-into-view.js +++ b/packages/block-editor/src/components/block-list/use-block-props/use-scroll-into-view.js @@ -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 ) { @@ -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(); } }