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

Site Editor > Styles: open styles inspector when clicking preview canvas #66996

Merged
merged 8 commits into from
Nov 14, 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
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
Loading