From 3b249d7216bc707bd2815a8eabd5a6db6b3d3eb5 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 23 Jun 2023 11:15:46 +0100 Subject: [PATCH] Fix Rename in Navigation on Browse Mode (#51791) * Ensure edits are passed to save * Ensure empty strings are invalid * Force break of long strings in menu titles --- .../index.js | 2 +- .../rename-modal.js | 13 ++++++++++++- .../use-navigation-menu-handlers.js | 6 +++++- .../index.js | 4 +++- .../components/sidebar-navigation-screen/style.scss | 2 ++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js index 6fae7b09261981..6bce0f356f7400 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js @@ -60,7 +60,7 @@ export default function SidebarNavigationScreenNavigationMenu() { useNavigationMenuHandlers(); const _handleDelete = () => handleDelete( navigationMenu ); - const _handleSave = () => handleSave( navigationMenu ); + const _handleSave = ( edits ) => handleSave( navigationMenu, edits ); const _handleDuplicate = () => handleDuplicate( navigationMenu ); if ( isLoading ) { diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/rename-modal.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/rename-modal.js index 99f674ba8bee3a..668179755ec35a 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/rename-modal.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/rename-modal.js @@ -11,9 +11,16 @@ import { import { __ } from '@wordpress/i18n'; import { useState } from '@wordpress/element'; +const notEmptyString = ( testString ) => testString?.trim()?.length > 0; + export default function RenameModal( { menuTitle, onClose, onSave } ) { const [ editedMenuTitle, setEditedMenuTitle ] = useState( menuTitle ); + const titleHasChanged = editedMenuTitle !== menuTitle; + + const isEditedMenuTitleValid = + titleHasChanged && notEmptyString( editedMenuTitle ); + return (
@@ -30,11 +37,15 @@ export default function RenameModal( { menuTitle, onClose, onSave } ) {