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

[WIP] Post Template: Add click handler for switching between selected blocks when clicking on the block preview #37519

Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
}

.block-editor-block-preview__live-content {
* {
pointer-events: none;
}

// Hide the block appender, as the block is not editable in this context.
.block-list-appender {
display: none;
Expand Down
15 changes: 13 additions & 2 deletions packages/block-library/src/post-template/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { memo, useMemo, useState } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import {
BlockContextProvider,
Expand Down Expand Up @@ -40,8 +40,19 @@ function PostTemplateBlockPreview( {
blocks,
} );

const handleOnClick = () => {
const { selectBlock } = useDispatch( blockEditorStore );

const handleOnClick = ( event ) => {
const blockElement = !! event.target.getAttribute( 'data-block' )
? event.target
: event.target.closest( '[data-block]' );
const clientId = blockElement.getAttribute( 'data-block' );
event.preventDefault();
event.stopPropagation();
setActiveBlockContextId( blockContextId );
if ( clientId ) {
selectBlock( clientId );
}
};

const style = {
Expand Down