Skip to content

Commit

Permalink
Use useLayoutEffect to compute the popover position (#23312)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Jun 19, 2020
1 parent 6f9217d commit d10ce4c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/components/src/popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useRef, useState, useEffect } from '@wordpress/element';
import {
useRef,
useState,
useEffect,
useLayoutEffect,
} from '@wordpress/element';
import { focus, getRectangleFromRange } from '@wordpress/dom';
import { ESCAPE } from '@wordpress/keycodes';
import deprecated from '@wordpress/deprecated';
Expand Down Expand Up @@ -267,7 +272,7 @@ const Popover = ( {
const [ containerResizeListener, contentSize ] = useResizeObserver();
noArrow = isExpanded || noArrow;

useEffect( () => {
useLayoutEffect( () => {
if ( isExpanded ) {
setClass( containerRef.current, 'is-without-arrow', noArrow );
setClass( containerRef.current, 'is-alternate', isAlternate );
Expand Down

0 comments on commit d10ce4c

Please sign in to comment.