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 Block: Fix issue with double-clicking "Create a new menu" causing duplicate menus. #67488

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
import { Warning } from '@wordpress/block-editor';
import { Button, Notice } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { createInterpolateElement } from '@wordpress/element';
import { useState, createInterpolateElement } from '@wordpress/element';

function DeletedNavigationWarning( { onCreateNew, isNotice = false } ) {
const [ isButtonDisabled, setIsButtonDisabled ] = useState( false );

const handleButtonClick = () => {
setIsButtonDisabled( true );
onCreateNew();
};
Comment on lines +12 to +15
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would personally choose to inline this function and as a nicety also pass the arguments through to onCreateNew, as this changes the type/signature of the prop.

It still works fine though, so these changes aren't strictly needed, I leave it as some thoughtful feedback. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@talldan Thank you so much for your feedback! I really appreciate your insight and will definitely keep this in mind for the future.


const message = createInterpolateElement(
__(
'Navigation Menu has been deleted or is unavailable. <button>Create a new Menu?</button>'
Expand All @@ -15,8 +22,10 @@ function DeletedNavigationWarning( { onCreateNew, isNotice = false } ) {
button: (
<Button
__next40pxDefaultSize
onClick={ onCreateNew }
onClick={ handleButtonClick }
variant="link"
disabled={ isButtonDisabled }
accessibleWhenDisabled
/>
),
}
Expand Down
Loading