Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge wrapper refs
  • Loading branch information
ciampo committed Feb 7, 2022
commit b5e2c39b36623152c485ffd20179e75452f88e69
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { css } from '@emotion/react';
*/
import { focus } from '@wordpress/dom';
import { useContext, useEffect, useMemo, useRef } from '@wordpress/element';
import { useReducedMotion } from '@wordpress/compose';
import { useReducedMotion, useMergeRefs } from '@wordpress/compose';
import { isRTL } from '@wordpress/i18n';

/**
Expand Down Expand Up @@ -99,13 +99,19 @@ function NavigatorScreen( props: Props, forwardedRef: Ref< any > ) {
elementToFocus.focus();
}, [ isInitialLocation, isMatch ] );

const mergedWrapperRef = useMergeRefs( [ forwardedRef, wrapperRef ] );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging the two refs, so that they are correctly assigned to the wrapper element regardless of the value of prefersReducedMotion


if ( ! isMatch ) {
return null;
}

if ( prefersReducedMotion ) {
return (
<View ref={ forwardedRef } className={ classes } { ...otherProps }>
<View
ref={ mergedWrapperRef }
className={ classes }
{ ...otherProps }
>
{ children }
</View>
);
Expand Down Expand Up @@ -148,7 +154,7 @@ function NavigatorScreen( props: Props, forwardedRef: Ref< any > ) {

return (
<motion.div
ref={ wrapperRef }
ref={ mergedWrapperRef }
className={ classes }
{ ...otherProps }
{ ...animatedProps }
Expand Down