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

Using selectBlock / selecting in custom block #5589

Closed
marcusig opened this issue Mar 13, 2018 · 4 comments
Closed

Using selectBlock / selecting in custom block #5589

marcusig opened this issue Mar 13, 2018 · 4 comments
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Enhancement A suggestion for improvement.

Comments

@marcusig
Copy link

Issue Overview

I'm working on a block that uses an iframe to render the content, a bit like embeds.
The issue is when clicking the content of the iframe the block doesn't get selected
(the same thing happens with media embeds).

Is there a function / abstraction we can use to programatically select a block?

@aduth
Copy link
Member

aduth commented Mar 14, 2018

Related: #483 (#483 (comment))

@aduth
Copy link
Member

aduth commented Mar 14, 2018

Technically this is possible by using the data module via the editor's action creators:

edit: withDispatch( ( dispatch, ownProps ) => {
	const { selectBlock } = dispatch( 'core/editor' );

	return {
		selectBlock: () => selectBlock( ownProps.id );
	};
} )( ( { /* attributes, ... , */ selectBlock } ) ) => {
	return /* ... */;
} );

It would probably be preferable for this to be a prop passed into the edit component natively though.

Also, don't rely on ownProps.id, as this may be normalized to uid in a future change.

@marcusig
Copy link
Author

marcusig commented Mar 14, 2018

Thanks. I'm going to try that. It would help to have it as a prop as you said.

@aduth aduth added [Feature] Block API API that allows to express the block paradigm. [Type] Enhancement A suggestion for improvement. labels Mar 14, 2018
@aduth
Copy link
Member

aduth commented Apr 13, 2018

This was not made as a prop as originally suggested, but you can now use the new wp.components.FocusableIframe component which will trigger a focus event as expected and interoperates with the block's default focus handler for selection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants