-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Reset focus after route navigation in Site Editor #37314
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1a88742
Refactor to use a common layout
kevin940726 d1f901d
Reset focus to navigation toggle button on route change
kevin940726 069a66e
Add missing shortcuts
kevin940726 e4029fd
Fix initial page redirection
kevin940726 3067f9a
Don't refocus if the activeElement is still on the page
kevin940726 46d1036
Remove temp hack
kevin940726 2157324
Fix GlobalStylesProvider's position
kevin940726 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 hidden or 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 |
|---|---|---|
| @@ -1,66 +1,56 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { SlotFillProvider } from '@wordpress/components'; | ||
| import { UnsavedChangesWarning } from '@wordpress/editor'; | ||
| import { store as noticesStore } from '@wordpress/notices'; | ||
| import { useDispatch } from '@wordpress/data'; | ||
| import { __, sprintf } from '@wordpress/i18n'; | ||
| import { PluginArea } from '@wordpress/plugins'; | ||
| import { useSelect } from '@wordpress/data'; | ||
| import { store as interfaceStore } from '@wordpress/interface'; | ||
| import { store as coreStore } from '@wordpress/core-data'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { Routes } from '../routes'; | ||
| import { store as editSiteStore } from '../../store'; | ||
| import { useLocation } from '../routes'; | ||
| import Editor from '../editor'; | ||
| import List from '../list'; | ||
| import NavigationSidebar from '../navigation-sidebar'; | ||
| import getIsListPage from '../../utils/get-is-list-page'; | ||
|
|
||
| export default function EditSiteApp( { reboot } ) { | ||
| const { createErrorNotice } = useDispatch( noticesStore ); | ||
| const { params } = useLocation(); | ||
| const { | ||
| isInserterOpen, | ||
| isListViewOpen, | ||
| sidebarIsOpened, | ||
| postType, | ||
| } = useSelect( | ||
| ( select ) => { | ||
| const { isInserterOpened, isListViewOpened } = select( | ||
| editSiteStore | ||
| ); | ||
|
|
||
| function onPluginAreaError( name ) { | ||
| createErrorNotice( | ||
| sprintf( | ||
| /* translators: %s: plugin name */ | ||
| __( | ||
| 'The "%s" plugin has encountered an error and cannot be rendered.' | ||
| ), | ||
| name | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <SlotFillProvider> | ||
| <UnsavedChangesWarning /> | ||
| // The currently selected entity to display. Typically template or template part. | ||
| return { | ||
| isInserterOpen: isInserterOpened(), | ||
| isListViewOpen: isListViewOpened(), | ||
| sidebarIsOpened: !! select( | ||
| interfaceStore | ||
| ).getActiveComplementaryArea( editSiteStore.name ), | ||
| postType: select( coreStore ).getPostType( params.postType ), | ||
| }; | ||
| }, | ||
| [ params.postType ] | ||
| ); | ||
|
|
||
| <Routes> | ||
| { ( { params } ) => { | ||
| const isListPage = getIsListPage( params ); | ||
| const isListPage = getIsListPage( params ); | ||
|
|
||
| return ( | ||
| <> | ||
| { isListPage ? ( | ||
| <List /> | ||
| ) : ( | ||
| <Editor onError={ reboot } /> | ||
| ) } | ||
| <PluginArea onError={ onPluginAreaError } /> | ||
| { /* Keep the instance of the sidebar to ensure focus will not be lost | ||
| * when navigating to other pages. */ } | ||
| <NavigationSidebar | ||
| // Open the navigation sidebar by default when in the list page. | ||
| isDefaultOpen={ !! isListPage } | ||
| activeTemplateType={ | ||
| isListPage ? params.postType : undefined | ||
| } | ||
| /> | ||
| </> | ||
| ); | ||
| } } | ||
| </Routes> | ||
| </SlotFillProvider> | ||
| ); | ||
| return isListPage | ||
| ? List.renderLayout( { | ||
| postType, | ||
| activeTemplateType: params.postType, | ||
| } ) | ||
| : Editor.renderLayout( { | ||
| isInserterOpen, | ||
| isListViewOpen, | ||
| sidebarIsOpened, | ||
| reboot, | ||
| } ); | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { useCallback } from '@wordpress/element'; | ||
| import { useSelect, useDispatch } from '@wordpress/data'; | ||
| import { Button } from '@wordpress/components'; | ||
| import { EntitiesSavedStates } from '@wordpress/editor'; | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { store as editSiteStore } from '../../store'; | ||
|
|
||
| export default function EditorActions() { | ||
|
||
| const isEntitiesSavedStatesOpen = useSelect( | ||
| ( select ) => select( editSiteStore ).getIsEntitiesSavedStatesOpen(), | ||
| [] | ||
| ); | ||
| const { setIsEntitiesSavedStatesOpen } = useDispatch( editSiteStore ); | ||
| const openEntitiesSavedStates = useCallback( | ||
| () => setIsEntitiesSavedStatesOpen( true ), | ||
| [ setIsEntitiesSavedStatesOpen ] | ||
| ); | ||
| const closeEntitiesSavedStates = useCallback( | ||
| () => setIsEntitiesSavedStatesOpen( false ), | ||
| [ setIsEntitiesSavedStatesOpen ] | ||
| ); | ||
|
|
||
| return isEntitiesSavedStatesOpen ? ( | ||
| <EntitiesSavedStates close={ closeEntitiesSavedStates } /> | ||
| ) : ( | ||
| <div className="edit-site-editor__toggle-save-panel"> | ||
| <Button | ||
| variant="secondary" | ||
| className="edit-site-editor__toggle-save-panel-button" | ||
| onClick={ openEntitiesSavedStates } | ||
| aria-expanded={ false } | ||
| > | ||
| { __( 'Open save panel' ) } | ||
| </Button> | ||
| </div> | ||
| ); | ||
| } | ||
Oops, something went wrong.
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.
<UnsavedChangesWarning>is moved to<Layout>.