Skip to content

Commit

Permalink
Fix regression with Navigation blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong committed Jan 14, 2022
1 parent d3bf1c0 commit 29774c9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
17 changes: 16 additions & 1 deletion packages/block-library/src/navigation-submenu/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,25 @@ import { speak } from '@wordpress/a11y';
*/
import { ItemSubmenuIcon } from './icons';
import { name } from './block.json';
import navigationLinkMetadata from '../navigation-link/block.json';

const ALLOWED_BLOCKS = [ 'core/navigation-link', 'core/navigation-submenu' ];

const DEFAULT_BLOCK = [ 'core/navigation-link' ];
const DEFAULT_BLOCK = [
'core/navigation-link',
{
...Object.entries( navigationLinkMetadata.attributes ).reduce(
( acc, attribute ) => ( {
...acc,
[ attribute[ 0 ] ]:
attribute[ 1 ].default !== undefined
? attribute[ 1 ].default
: undefined,
} ),
{}
),
},
];

const MAX_NESTING = 5;

Expand Down
18 changes: 17 additions & 1 deletion packages/block-library/src/navigation/edit/inner-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useMemo } from '@wordpress/element';
* Internal dependencies
*/
import PlaceholderPreview from './placeholder/placeholder-preview';
import navigationLinkMetadata from '../../navigation-link/block.json';

const ALLOWED_BLOCKS = [
'core/navigation-link',
Expand All @@ -27,7 +28,22 @@ const ALLOWED_BLOCKS = [
'core/navigation-submenu',
];

const DEFAULT_BLOCK = [ 'core/navigation-link' ];
// Set default block to use default or undefined attribute values when inserted.
const DEFAULT_BLOCK = [
'core/navigation-link',
{
...Object.entries( navigationLinkMetadata.attributes ).reduce(
( acc, attribute ) => ( {
...acc,
[ attribute[ 0 ] ]:
attribute[ 1 ].default !== undefined
? attribute[ 1 ].default
: undefined,
} ),
{}
),
},
];

const LAYOUT = {
type: 'default',
Expand Down

0 comments on commit 29774c9

Please sign in to comment.