Skip to content

Commit

Permalink
Styles Screen: Ensure variations previews will render in mobile viewp…
Browse files Browse the repository at this point in the history
…orts (#51080)
  • Loading branch information
andrewserong authored May 30, 2023
1 parent 6a06d08 commit 350a916
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useSelect, useDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { __experimentalNavigatorButton as NavigatorButton } from '@wordpress/components';
import { useViewportMatch } from '@wordpress/compose';
import { BlockEditorProvider } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -19,6 +20,8 @@ import SidebarButton from '../sidebar-button';
import SidebarNavigationItem from '../sidebar-navigation-item';
import StyleBook from '../style-book';

const noop = () => {};

export function SidebarNavigationItemGlobalStyles( props ) {
const { openGeneralSidebar } = useDispatch( editSiteStore );
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
Expand Down Expand Up @@ -51,6 +54,33 @@ export function SidebarNavigationItemGlobalStyles( props ) {
);
}

function SidebarNavigationScreenGlobalStylesContent() {
const { storedSettings } = useSelect( ( select ) => {
const { getSettings } = unlock( select( editSiteStore ) );

return {
storedSettings: getSettings( false ),
};
}, [] );

// Wrap in a BlockEditorProvider to ensure that the Iframe's dependencies are
// loaded. This is necessary because the Iframe component waits until
// the block editor store's `__internalIsInitialized` is true before
// rendering the iframe. Without this, the iframe previews will not render
// in mobile viewport sizes, where the editor canvas is hidden.
return (
<BlockEditorProvider
settings={ storedSettings }
onChange={ noop }
onInput={ noop }
>
<div className="edit-site-sidebar-navigation-screen-global-styles__content">
<StyleVariationsContainer />
</div>
</BlockEditorProvider>
);
}

export default function SidebarNavigationScreenGlobalStyles() {
const { openGeneralSidebar } = useDispatch( editSiteStore );
const isMobileViewport = useViewportMatch( 'medium', '<' );
Expand Down Expand Up @@ -86,7 +116,7 @@ export default function SidebarNavigationScreenGlobalStyles() {
description={ __(
'Choose a different style combination for the theme styles.'
) }
content={ <StyleVariationsContainer /> }
content={ <SidebarNavigationScreenGlobalStylesContent /> }
actions={
<div>
{ ! isMobileViewport && (
Expand Down

1 comment on commit 350a916

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 350a916.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5127241823
📝 Reported issues:

Please sign in to comment.