Skip to content

Commit

Permalink
Site Editor > Styles: open styles inspector when clicking preview can…
Browse files Browse the repository at this point in the history
…vas (#66996)

Co-authored-by: ellatrix <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: jasmussen <[email protected]>
  • Loading branch information
4 people authored Nov 14, 2024
1 parent cd5ead1 commit 2e5ba3b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/edit-site/src/components/global-styles-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 (
<DefaultSidebar
className="edit-site-global-styles-sidebar"
Expand Down

0 comments on commit 2e5ba3b

Please sign in to comment.