Skip to content

Commit

Permalink
Update remaining useAnchorRef usages, switch to the anchor prop
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Aug 30, 2022
1 parent ac5c6ed commit b65140f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/components/src/autocomplete/autocompleter-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function getAutoCompleterUI( autocompleter ) {
contentRef,
} ) {
const [ items ] = useItems( filterValue );
const anchorRef = useAnchorRef( { ref: contentRef, value } );
const popoverAnchor = useAnchorRef( { ref: contentRef, value } );

useLayoutEffect( () => {
onChangeOptions( items );
Expand All @@ -54,7 +54,7 @@ export function getAutoCompleterUI( autocompleter ) {
onClose={ onReset }
position="top right"
className="components-autocomplete__popover"
anchorRef={ anchorRef }
anchor={ popoverAnchor }
>
<div
id={ listBoxId }
Expand Down
4 changes: 2 additions & 2 deletions packages/format-library/src/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const image = {
function InlineUI( { value, onChange, activeObjectAttributes, contentRef } ) {
const { style } = activeObjectAttributes;
const [ width, setWidth ] = useState( style?.replace( /\D/g, '' ) );
const anchorRef = useAnchorRef( {
const popoverAnchor = useAnchorRef( {
ref: contentRef,
value,
settings: image,
Expand All @@ -46,7 +46,7 @@ function InlineUI( { value, onChange, activeObjectAttributes, contentRef } ) {
<Popover
position="bottom center"
focusOnMount={ false }
anchorRef={ anchorRef }
anchor={ popoverAnchor }
className="block-editor-format-toolbar__image-popover"
>
<form
Expand Down
6 changes: 3 additions & 3 deletions packages/format-library/src/link/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ function InlineLinkUI( {
}
}

const anchorRef = useAnchorRef( { ref: contentRef, value, settings } );
const popoverAnchor = useAnchorRef( { ref: contentRef, value, settings } );

// Generate a string based key that is unique to this anchor reference.
// This is used to force re-mount the LinkControl component to avoid
// potential stale state bugs caused by the component not being remounted
// See https://github.com/WordPress/gutenberg/pull/34742.
const forceRemountKey = useLinkInstanceKey( anchorRef );
const forceRemountKey = useLinkInstanceKey( popoverAnchor );

// The focusOnMount prop shouldn't evolve during render of a Popover
// otherwise it causes a render of the content.
Expand Down Expand Up @@ -223,7 +223,7 @@ function InlineLinkUI( {

return (
<Popover
anchorRef={ anchorRef }
anchor={ popoverAnchor }
focusOnMount={ focusOnMount.current }
onClose={ stopAddingLink }
position="bottom center"
Expand Down
6 changes: 3 additions & 3 deletions packages/format-library/src/text-color/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,22 @@ export default function InlineColorUI( {
onClose,
contentRef,
} ) {
/*
/*
As you change the text color by typing a HEX value into a field,
the return value of document.getSelection jumps to the field you're editing,
not the highlighted text. Given that useAnchorRef uses document.getSelection,
it will return null, since it can't find the <mark> element within the HEX input.
This caches the last truthy value of the selection anchor reference.
*/
const anchorRef = useCachedTruthy(
const popoverAnchor = useCachedTruthy(
useAnchorRef( { ref: contentRef, value, settings } )
);

return (
<Popover
onClose={ onClose }
className="components-inline-color-popover"
anchorRef={ anchorRef }
anchor={ popoverAnchor }
>
<TabPanel
tabs={ [
Expand Down

0 comments on commit b65140f

Please sign in to comment.