From 336a4b479cf5ff6df25718403a0c7f543049ea2d Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Tue, 6 Sep 2022 11:26:27 +0200 Subject: [PATCH] Edit Post: use Popover's new anchor prop (#43808) * Edit Post: use Popover s new anchor prop * Update comment * SImplify code * Update packages/edit-post/src/components/sidebar/post-schedule/index.js Co-authored-by: Daniel Richards * Allow passing a `null` anchor Co-authored-by: Daniel Richards --- .../src/components/sidebar/post-schedule/index.js | 14 ++++++++++---- .../components/sidebar/post-schedule/style.scss | 2 +- .../src/components/sidebar/post-template/index.js | 10 ++++++---- .../src/components/sidebar/post-url/index.js | 11 +++++++---- .../components/sidebar/post-visibility/index.js | 14 ++++++++++---- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/packages/edit-post/src/components/sidebar/post-schedule/index.js b/packages/edit-post/src/components/sidebar/post-schedule/index.js index f8b96fe6669e7b..cf1c64fa792894 100644 --- a/packages/edit-post/src/components/sidebar/post-schedule/index.js +++ b/packages/edit-post/src/components/sidebar/post-schedule/index.js @@ -3,7 +3,7 @@ */ import { __, sprintf } from '@wordpress/i18n'; import { PanelRow, Dropdown, Button } from '@wordpress/components'; -import { useRef } from '@wordpress/element'; +import { useState } from '@wordpress/element'; import { PostSchedule as PostScheduleForm, PostScheduleCheck, @@ -11,13 +11,19 @@ import { } from '@wordpress/editor'; export default function PostSchedule() { - const anchorRef = useRef(); + // Use internal state instead of a ref to make sure that the component + // re-renders when the anchor's ref updates. + const [ popoverAnchor, setPopoverAnchor ] = useState( null ); + return ( - + { __( 'Publish' ) } { const postTypeSlug = select( editorStore ).getCurrentPostType(); @@ -46,10 +48,10 @@ export default function PostTemplate() { } return ( - + { __( 'Template' ) } - + { __( 'URL' ) } ( - + { __( 'Visibility' ) } { ! canEdit && ( @@ -31,7 +37,7 @@ export function PostVisibility() { // Anchor the popover to the middle of the // entire row so that it doesn't move around // when the label changes. - anchorRef: rowRef.current, + anchor: popoverAnchor, } } focusOnMount renderToggle={ ( { isOpen, onToggle } ) => (