-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix navigation select menu focus loss #42956
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,7 +191,6 @@ function Navigation( { | |
isNavigationMenuResolved, | ||
isNavigationMenuMissing, | ||
navigationMenus, | ||
navigationMenu, | ||
canUserUpdateNavigationMenu, | ||
hasResolvedCanUserUpdateNavigationMenu, | ||
canUserDeleteNavigationMenu, | ||
|
@@ -240,8 +239,6 @@ function Navigation( { | |
|
||
const navRef = useRef(); | ||
|
||
const isDraftNavigationMenu = navigationMenu?.status === 'draft'; | ||
|
||
const { | ||
convert: convertClassicMenu, | ||
status: classicMenuConversionStatus, | ||
|
@@ -331,11 +328,6 @@ function Navigation( { | |
] = useState(); | ||
const [ detectedOverlayColor, setDetectedOverlayColor ] = useState(); | ||
|
||
const handleUpdateMenu = ( menuId ) => { | ||
setRef( menuId ); | ||
selectBlock( clientId ); | ||
}; | ||
|
||
useEffect( () => { | ||
hideClassicMenuConversionNotice(); | ||
if ( classicMenuConversionStatus === CLASSIC_MENU_CONVERSION_PENDING ) { | ||
|
@@ -426,27 +418,6 @@ function Navigation( { | |
ref, | ||
] ); | ||
|
||
const navigationSelectorRef = useRef(); | ||
const [ shouldFocusNavigationSelector, setShouldFocusNavigationSelector ] = | ||
useState( false ); | ||
|
||
// Focus support after menu selection. | ||
useEffect( () => { | ||
if ( | ||
isDraftNavigationMenu || | ||
! isEntityAvailable || | ||
! shouldFocusNavigationSelector | ||
) { | ||
return; | ||
} | ||
navigationSelectorRef?.current?.focus(); | ||
setShouldFocusNavigationSelector( false ); | ||
}, [ | ||
isDraftNavigationMenu, | ||
isEntityAvailable, | ||
shouldFocusNavigationSelector, | ||
] ); | ||
getdave marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const isResponsive = 'never' !== overlayMenu; | ||
|
||
const overlayMenuPreviewClasses = classnames( | ||
|
@@ -598,21 +569,16 @@ function Navigation( { | |
<BlockControls> | ||
<ToolbarGroup className="wp-block-navigation__toolbar-menu-selector"> | ||
<NavigationMenuSelector | ||
ref={ null } | ||
currentMenuId={ null } | ||
currentMenuId={ ref } | ||
clientId={ clientId } | ||
onSelectNavigationMenu={ ( menuId ) => { | ||
handleUpdateMenu( menuId ); | ||
setShouldFocusNavigationSelector( true ); | ||
} } | ||
onSelectNavigationMenu={ setRef } | ||
onSelectClassicMenu={ async ( classicMenu ) => { | ||
const navMenu = await convertClassicMenu( | ||
classicMenu.id, | ||
classicMenu.name | ||
); | ||
if ( navMenu ) { | ||
handleUpdateMenu( navMenu.id ); | ||
setShouldFocusNavigationSelector( true ); | ||
setRef( navMenu.id ); | ||
} | ||
} } | ||
onCreateNew={ () => createNavigationMenu( '', [] ) } | ||
|
@@ -658,28 +624,22 @@ function Navigation( { | |
} | ||
|
||
// Show a warning if the selected menu is no longer available. | ||
// TODO - the user should be able to select a new one? | ||
if ( ref && isNavigationMenuMissing ) { | ||
return ( | ||
<TagName { ...blockProps }> | ||
<BlockControls> | ||
<ToolbarGroup className="wp-block-navigation__toolbar-menu-selector"> | ||
<NavigationMenuSelector | ||
ref={ navigationSelectorRef } | ||
currentMenuId={ ref } | ||
clientId={ clientId } | ||
onSelectNavigationMenu={ ( menuId ) => { | ||
handleUpdateMenu( menuId ); | ||
setShouldFocusNavigationSelector( true ); | ||
} } | ||
onSelectNavigationMenu={ setRef } | ||
onSelectClassicMenu={ async ( classicMenu ) => { | ||
const navMenu = await convertClassicMenu( | ||
classicMenu.id, | ||
classicMenu.name | ||
); | ||
if ( navMenu ) { | ||
handleUpdateMenu( navMenu.id ); | ||
setShouldFocusNavigationSelector( true ); | ||
setRef( navMenu.id ); | ||
} | ||
} } | ||
onCreateNew={ () => createNavigationMenu( '', [] ) } | ||
|
@@ -740,17 +700,17 @@ function Navigation( { | |
isResolvingCanUserCreateNavigationMenu | ||
} | ||
onSelectNavigationMenu={ ( menuId ) => { | ||
handleUpdateMenu( menuId ); | ||
setShouldFocusNavigationSelector( true ); | ||
setRef( menuId ); | ||
selectBlock( clientId ); | ||
} } | ||
onSelectClassicMenu={ async ( classicMenu ) => { | ||
const navMenu = await convertClassicMenu( | ||
classicMenu.id, | ||
classicMenu.name | ||
); | ||
if ( navMenu ) { | ||
handleUpdateMenu( navMenu.id ); | ||
setShouldFocusNavigationSelector( true ); | ||
setRef( navMenu.id ); | ||
selectBlock( clientId ); | ||
} | ||
} } | ||
onCreateEmpty={ () => createNavigationMenu( '', [] ) } | ||
|
@@ -763,37 +723,26 @@ function Navigation( { | |
<EntityProvider kind="postType" type="wp_navigation" id={ ref }> | ||
<RecursionProvider uniqueId={ recursionId }> | ||
<BlockControls> | ||
{ ! isDraftNavigationMenu && isEntityAvailable && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think these conditions do anything important, because there are already early returns in the component for missing entities or unselected menus. |
||
<ToolbarGroup className="wp-block-navigation__toolbar-menu-selector"> | ||
<NavigationMenuSelector | ||
ref={ navigationSelectorRef } | ||
currentMenuId={ ref } | ||
clientId={ clientId } | ||
onSelectNavigationMenu={ ( menuId ) => { | ||
handleUpdateMenu( menuId ); | ||
setShouldFocusNavigationSelector( true ); | ||
} } | ||
onSelectClassicMenu={ async ( classicMenu ) => { | ||
const navMenu = await convertClassicMenu( | ||
classicMenu.id, | ||
classicMenu.name | ||
); | ||
if ( navMenu ) { | ||
handleUpdateMenu( navMenu.id ); | ||
setShouldFocusNavigationSelector( | ||
true | ||
); | ||
} | ||
} } | ||
onCreateNew={ () => | ||
createNavigationMenu( '', [] ) | ||
<ToolbarGroup className="wp-block-navigation__toolbar-menu-selector"> | ||
<NavigationMenuSelector | ||
currentMenuId={ ref } | ||
clientId={ clientId } | ||
onSelectNavigationMenu={ setRef } | ||
onSelectClassicMenu={ async ( classicMenu ) => { | ||
const navMenu = await convertClassicMenu( | ||
classicMenu.id, | ||
classicMenu.name | ||
); | ||
if ( navMenu ) { | ||
setRef( navMenu.id ); | ||
} | ||
/* translators: %s: The name of a menu. */ | ||
actionLabel={ __( "Switch to '%s'" ) } | ||
showManageActions | ||
/> | ||
</ToolbarGroup> | ||
) } | ||
} } | ||
onCreateNew={ () => createNavigationMenu( '', [] ) } | ||
/* translators: %s: The name of a menu. */ | ||
actionLabel={ __( "Switch to '%s'" ) } | ||
showManageActions | ||
/> | ||
</ToolbarGroup> | ||
</BlockControls> | ||
{ stylingInspectorControls } | ||
{ isEntityAvailable && ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be unused. Previously, 'unsaved inner blocks' when saved were created as drafts, but that was accidentally removed months ago by some refactoring and no-one really complained, so I'll remove this as well. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I think @draganescu might need it back very shortly 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was exploring the idea of saving menus as drafts initially indifferent of how they're created so the user does the "final call" action when clicking save. The idea is to avoid fiddling with live site menus by mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth noting that there's still some code that changes the status to
publish
when saving wp_navigation entities in an editor:gutenberg/packages/editor/src/components/entities-saved-states/index.js
Lines 32 to 37 in 54c9d81
gutenberg/packages/editor/src/components/entities-saved-states/index.js
Lines 149 to 157 in 54c9d81
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@draganescu Let me know what you'd like me to do. I can make a separate PR that removes all of the draft handling, which you can revert when you need it back. Or I can put
isDraftNavigationMenu
back in this PRThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should proceed as things are no need for any separate PR. We'll see how trunk looks when we start changing the publish behavior 🙏🏻