Skip to content

Commit

Permalink
Fix: Custom color formatter may end up "bouncing" (#20612)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Mar 10, 2020
1 parent 0d31aaf commit d965f07
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/format-library/src/text-color/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export function getActiveColor( formatName, formatValue, colors ) {
}
}

const ColorPopoverAtLink = ( { isActive, addingColor, value, ...props } ) => {
const ColorPopoverAtLink = ( { addingColor, ...props } ) => {
// There is no way to open a text formatter popover when another one is mounted.
// The first popover will always be dismounted when a click outside happens, so we can store the
// anchor Rect during the lifetime of the component.
const anchorRect = useMemo( () => {
const selection = window.getSelection();
const range =
Expand All @@ -65,7 +68,7 @@ const ColorPopoverAtLink = ( { isActive, addingColor, value, ...props } ) => {
if ( closest ) {
return closest.getBoundingClientRect();
}
}, [ isActive, addingColor, value.start, value.end ] );
}, [] );

if ( ! anchorRect ) {
return null;
Expand Down

0 comments on commit d965f07

Please sign in to comment.