From c05b770a54b7228eda57b48621ac52029f526c19 Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Tue, 30 Aug 2022 16:41:05 +0200 Subject: [PATCH] Update useAnchorRef usage in FormatToolbarContainer, use anchor prop --- .../rich-text/format-toolbar-container.js | 22 +++++++++++-------- .../src/components/rich-text/index.js | 2 +- .../src/components/rich-text/index.native.js | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/format-toolbar-container.js b/packages/block-editor/src/components/rich-text/format-toolbar-container.js index 24a931dc791754..94610af8fcda1a 100644 --- a/packages/block-editor/src/components/rich-text/format-toolbar-container.js +++ b/packages/block-editor/src/components/rich-text/format-toolbar-container.js @@ -17,28 +17,32 @@ import BlockControls from '../block-controls'; import FormatToolbar from './format-toolbar'; import { store as blockEditorStore } from '../../store'; -function InlineSelectionToolbar( { value, anchorRef, activeFormats } ) { +function InlineSelectionToolbar( { + value, + editableContentRef, + activeFormats, +} ) { const lastFormat = activeFormats[ activeFormats.length - 1 ]; const lastFormatType = lastFormat?.type; const settings = useSelect( ( select ) => select( richTextStore ).getFormatType( lastFormatType ), [ lastFormatType ] ); - const selectionRef = useAnchorRef( { - ref: anchorRef, + const popoverAnchor = useAnchorRef( { + ref: editableContentRef, value, settings, } ); - return ; + return ; } -function InlineToolbar( { anchorRef } ) { +function InlineToolbar( { popoverAnchor } ) { return ( @@ -51,14 +55,14 @@ function InlineToolbar( { anchorRef } ) { ); } -const FormatToolbarContainer = ( { inline, anchorRef, value } ) => { +const FormatToolbarContainer = ( { inline, editableContentRef, value } ) => { const hasInlineToolbar = useSelect( ( select ) => select( blockEditorStore ).getSettings().hasInlineToolbar, [] ); if ( inline ) { - return ; + return ; } if ( hasInlineToolbar ) { @@ -70,7 +74,7 @@ const FormatToolbarContainer = ( { inline, anchorRef, value } ) => { return ( diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index 21c004b225f6c5..ae0942349b90c8 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -354,7 +354,7 @@ function RichTextWrapper( { isSelected && hasFormats && ( ) } diff --git a/packages/block-editor/src/components/rich-text/index.native.js b/packages/block-editor/src/components/rich-text/index.native.js index fe04011866fd8d..5c1008095b05ae 100644 --- a/packages/block-editor/src/components/rich-text/index.native.js +++ b/packages/block-editor/src/components/rich-text/index.native.js @@ -659,7 +659,7 @@ function RichTextWrapper( { nestedIsSelected && hasFormats && ( ) } { nestedIsSelected && }