Skip to content

Commit

Permalink
Fix submenu layout in navigation page list. (#34342)
Browse files Browse the repository at this point in the history
* Fix submenu layout in navigation page list.

* Update parent status before component renders.
  • Loading branch information
tellthemachines authored Aug 30, 2021
1 parent b4e74b7 commit ec62e53
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/block-library/src/page-list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -70,11 +69,6 @@ export default function PageListEdit( {
context.customOverlayBackgroundColor,
] );

useEffect( () => {
const isNavigationChild = isEmpty( context ) ? false : true;
setAttributes( { isNavigationChild } );
}, [] );

const { textColor, backgroundColor, showSubmenuIcon, style } =
context || {};

Expand Down Expand Up @@ -105,6 +99,10 @@ export default function PageListEdit( {
[ clientId ]
);

useEffect( () => {
setAttributes( { isNavigationChild: isParentNavigation } );
}, [] );

useEffect( () => {
if ( isParentNavigation ) {
apiFetch( {
Expand All @@ -127,6 +125,12 @@ export default function PageListEdit( {
const openModal = () => setOpen( true );
const closeModal = () => setOpen( false );

// Update parent status before component first renders.
const attributesWithParentStatus = {
...attributes,
isNavigationChild: isParentNavigation,
};

return (
<>
{ allowConvertToLinks && (
Expand All @@ -145,7 +149,7 @@ export default function PageListEdit( {
<div { ...blockProps }>
<ServerSideRender
block="core/page-list"
attributes={ attributes }
attributes={ attributesWithParentStatus }
/>
</div>
</>
Expand Down

0 comments on commit ec62e53

Please sign in to comment.