Skip to content

Commit

Permalink
Allow passing a null anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Sep 6, 2022
1 parent 562e23c commit 1e3184a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
export default function PostSchedule() {
// 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();
const [ popoverAnchor, setPopoverAnchor ] = useState( null );

return (
<PostScheduleCheck>
Expand All @@ -23,10 +23,7 @@ export default function PostSchedule() {
>
<span>{ __( 'Publish' ) }</span>
<Dropdown
popoverProps={ {
// `anchor` can not be `null`
anchor: popoverAnchor ?? undefined,
} }
popoverProps={ { anchor: popoverAnchor } }
position="bottom left"
contentClassName="edit-post-post-schedule__dialog"
focusOnMount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { store as editPostStore } from '../../../store';
export default function PostTemplate() {
// Use internal state instead of a ref to make sure that the component
// re-renders when then anchor's ref updates.
const [ popoverAnchor, setPopoverAnchor ] = useState();
const [ popoverAnchor, setPopoverAnchor ] = useState( null );

const isVisible = useSelect( ( select ) => {
const postTypeSlug = select( editorStore ).getCurrentPostType();
Expand Down Expand Up @@ -51,10 +51,7 @@ export default function PostTemplate() {
<PanelRow className="edit-post-post-template" ref={ setPopoverAnchor }>
<span>{ __( 'Template' ) }</span>
<Dropdown
popoverProps={ {
// `anchor` can not be `null`
anchor: popoverAnchor ?? undefined,
} }
popoverProps={ { anchor: popoverAnchor } }
position="bottom left"
className="edit-post-post-template__dropdown"
contentClassName="edit-post-post-template__dialog"
Expand Down
7 changes: 2 additions & 5 deletions packages/edit-post/src/components/sidebar/post-url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ import {
export default function PostURL() {
// Use internal state instead of a ref to make sure that the component
// re-renders when then anchor's ref updates.
const [ popoverAnchor, setPopoverAnchor ] = useState();
const [ popoverAnchor, setPopoverAnchor ] = useState( null );

return (
<PostURLCheck>
<PanelRow className="edit-post-post-url" ref={ setPopoverAnchor }>
<span>{ __( 'URL' ) }</span>
<Dropdown
popoverProps={ {
// `anchor` can not be `null`
anchor: popoverAnchor ?? undefined,
} }
popoverProps={ { anchor: popoverAnchor } }
position="bottom left"
className="edit-post-post-url__dropdown"
contentClassName="edit-post-post-url__dialog"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useState } from '@wordpress/element';
export function PostVisibility() {
// Use internal state instead of a ref to make sure that the component
// re-renders when then anchor's ref updates.
const [ popoverAnchor, setPopoverAnchor ] = useState();
const [ popoverAnchor, setPopoverAnchor ] = useState( null );

return (
<PostVisibilityCheck
Expand All @@ -37,8 +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.
// `anchor` can not be `null`
anchor: popoverAnchor ?? undefined,
anchor: popoverAnchor,
} }
focusOnMount
renderToggle={ ( { isOpen, onToggle } ) => (
Expand Down

0 comments on commit 1e3184a

Please sign in to comment.