Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation: Surface menu name in the List View next to the Navigation block #68446

Open
wants to merge 9 commits into
base: trunk
Choose a base branch
from
25 changes: 24 additions & 1 deletion packages/block-library/src/navigation/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { navigation as icon } from '@wordpress/icons';
import { select } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
Expand Down Expand Up @@ -52,6 +55,26 @@ export const settings = {
},
edit,
save,
__experimentalLabel: ( { ref } ) => {
if ( ! ref ) {
return __( 'Navigation' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The block title may have changed. Example code:

function change_navigation_block_name( $args, $block_type ) {
	if ( 'core/navigation' !== $block_type ) {
		return $args;
	}
	$args['title'] = __( 'My Navigation!' );
	return $args;
}
add_filter( "register_block_type_args", "change_navigation_block_name", 10, 2 );

Should this possibility be considered?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can return undefined here. This will signal the block editor to display the block's default title.

See the Template Part block for a similar example:

if ( ! slug ) {
return;
}

}

const navigation = select( coreStore ).getEditedEntityRecord(
'postType',
'wp_navigation',
ref
);

return navigation?.title
? sprintf(
/* translators: %1$s: block title, %2$s: navigation menu title */
__( '%1$s (%2$s)' ),
metadata.title,
decodeEntities( navigation.title )
)
: __( 'Navigation' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Let's return undefined when Navigation has no title. You can use early return to make things more readable, IMO.

},
deprecated,
};

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/navigation-list-view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ test.describe( 'Navigation block - List view editing', () => {

await editor.openDocumentSettingsSidebar();

await page.getByLabel( 'Test Menu' ).click();
await page.getByLabel( 'Test Menu', { exact: true } ).click();

await page.keyboard.press( 'ArrowUp' );

Expand Down
9 changes: 8 additions & 1 deletion test/e2e/specs/site-editor/navigation-editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ test.describe( 'Editing Navigation Menus', () => {
canvas: 'edit',
} );

// Wait for the toggle to be visible.
await expect(
page.locator(
'.editor-document-tools__document-overview-toggle'
)
).toBeVisible();
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved

// Open List View.
await pageUtils.pressKeys( 'access+o' );

Expand All @@ -54,7 +61,7 @@ test.describe( 'Editing Navigation Menus', () => {
await expect( listView ).toBeVisible();

const navBlockNode = listView.getByRole( 'link', {
name: 'Navigation',
name: 'Navigation (Primary Menu)',
exact: true,
} );

Expand Down
Loading