diff --git a/packages/edit-site/src/components/global-styles-sidebar/index.js b/packages/edit-site/src/components/global-styles-sidebar/index.js index c0ad313d5d477c..b1cf4fec92c86e 100644 --- a/packages/edit-site/src/components/global-styles-sidebar/index.js +++ b/packages/edit-site/src/components/global-styles-sidebar/index.js @@ -5,7 +5,7 @@ import { FlexItem, Flex, Button } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { styles, seen, backup } from '@wordpress/icons'; import { useSelect, useDispatch } from '@wordpress/data'; -import { useEffect } from '@wordpress/element'; +import { useEffect, useRef } from '@wordpress/element'; import { store as preferencesStore } from '@wordpress/preferences'; import { store as editorStore, @@ -29,7 +29,7 @@ const { useLocation } = unlock( routerPrivateApis ); export default function GlobalStylesSidebar() { const { params } = useLocation(); - const { canvas = 'view' } = params; + const { canvas = 'view', path } = params; const { shouldClearCanvasContainerView, isStyleBookOpened, @@ -128,6 +128,20 @@ export default function GlobalStylesSidebar() { ); }; + const { getActiveComplementaryArea } = useSelect( interfaceStore ); + const { enableComplementaryArea } = useDispatch( interfaceStore ); + const previousActiveAreaRef = useRef( null ); + + useEffect( () => { + if ( path === '/wp_global_styles' && canvas === 'edit' ) { + previousActiveAreaRef.current = + getActiveComplementaryArea( 'core' ); + enableComplementaryArea( 'core', 'edit-site/global-styles' ); + } else if ( previousActiveAreaRef.current ) { + enableComplementaryArea( 'core', previousActiveAreaRef.current ); + } + }, [ path, enableComplementaryArea, canvas, getActiveComplementaryArea ] ); + return (