Skip to content

Embed Block: Refactor setting panel to use ToolsPanel #69636

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

Conversation

shimotmk
Copy link
Contributor

What?

Part of #67813

Make the settings panel more consistent with other blocks

Testing Instructions

  1. Open a post or page.
  2. Insert a embed block
  3. Open the settings panel
  4. You can see that you can set it up just like before Media settings.
<!-- wp:embed /-->

<!-- wp:embed {"url":"https://www.youtube.com/watch?v=Ok6JKHMAkH8\u0026t","type":"video","providerNameSlug":"youtube","responsive":true,"className":"add wp-embed-aspect-16-9 wp-has-aspect-ratio"} -->
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube add wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
https://www.youtube.com/watch?v=Ok6JKHMAkH8&amp;t
</div></figure>
<!-- /wp:embed -->

<!-- wp:embed {"url":"https://twitter.com/WordPress/status/1902028052193792485","type":"rich","providerNameSlug":"twitter","responsive":true,"className":"add"} -->
<figure class="wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter add"><div class="wp-block-embed__wrapper">
https://twitter.com/WordPress/status/1902028052193792485
</div></figure>
<!-- /wp:embed -->

<!-- wp:embed {"url":"https://wordpress.org/about/","type":"wp-embed","providerNameSlug":"wordpress-org"} -->
<figure class="wp-block-embed is-type-wp-embed is-provider-wordpress-org wp-block-embed-wordpress-org"><div class="wp-block-embed__wrapper">
https://wordpress.org/about/
</div></figure>
<!-- /wp:embed -->

Screenshots or screencast

before

before.mp4

after

after.mp4

Copy link

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core, Gutenberg Plugin.
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

Copy link

github-actions bot commented Mar 20, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: shimotmk <shimotomoki@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: carolinan <poena@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@carolinan
Copy link
Contributor

Hi
Can you please explain how the className changes are related to the ToolsPanel, it is not clear to me only from reading the code.

@carolinan
Copy link
Contributor

I copied this from the editor after placing the example code in my post.

On trunk, without the PR:

<figure tabindex="0" draggable="true"
class="block-editor-block-list__block wp-block add wp-embed-aspect-16-9 wp-has-aspect-ratio wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube"

With the PR applied:

<figure tabindex="0" draggable="true" 
class="block-editor-block-list__block wp-block add wp-embed-aspect-16-9 wp-has-aspect-ratio wp-block-embed add wp-embed-aspect-16-9 wp-has-aspect-ratio is-type-video is-provider-youtube wp-block-embed-youtube"

I don't think these duplicated class names are correct?

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

What do you think about the approach of making toggleResponsive a function? If we do that, we won't need to add new props to the EmbedControls component.

I think it would look something like this:

function toggleResponsive( newAllowResponsive ) {
	const { className } = attributes;
	const { html } = preview;
	setAttributes( {
		allowResponsive: newAllowResponsive,
		className: getClassNames(
			html,
			className,
			responsive && newAllowResponsive
		),
	} );
}

@shimotmk shimotmk force-pushed the enhancement/refactor-embed-block-control-panel branch from aa4f9b8 to 7b2d957 Compare May 25, 2025 21:08
@shimotmk
Copy link
Contributor Author

shimotmk commented May 25, 2025

Thanks for the review.
The new toggleResponsive seems to work fine!

I don't think these duplicated class names are correct?

The duplicate class names seem to be a separate issue.
I won't fix it in this PR, but will make a separate one.
This also occurs in trunk.

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

LGTM! Finally, could you merge the trunk branch into this PR or rebase this PR with the trunk branch?

I don't think these duplicated class names are correct?

This issue can be reproduced on trunk by following the steps below:

  • Insert an Embed block.
  • Embed a YouTube URL (Example: https://www.youtube.com/watch?v=Ok6JKHMAkH8)
  • Class names:
    • block-editor-block-list__block
    • wp-block
    • is-selected
    • wp-embed-aspect-16-9
    • wp-has-aspect-ratio
    • wp-block-embed
    • is-type-video
    • is-provider-youtube
    • wp-block-embed-youtube,
  • Disable the "Resize for smaller devices" setting.
  • Class names:
    • block-editor-block-list__block
    • wp-block
    • is-selected
    • wp-block-embed
    • is-type-video
    • is-provider-youtube
    • wp-block-embed-youtube
  • Enable the "Resize for smaller devices" setting again.
  • Class names:
    • block-editor-block-list__block
    • wp-block
    • is-selected
    • wp-embed-aspect-16-9
    • wp-has-aspect-ratio
    • wp-block-embed
    • wp-embed-aspect-16-9
    • wp-has-aspect-ratio
    • is-type-video
    • is-provider-youtube,
    • `wp-block-embed-youtube

This issue only occurs in the editor and is not caused by this PR.

shimotmk and others added 6 commits May 26, 2025 18:13
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
@shimotmk shimotmk force-pushed the enhancement/refactor-embed-block-control-panel branch from 3bebe8c to 5565ca3 Compare May 26, 2025 09:14
@t-hamano t-hamano merged commit 5d41556 into WordPress:trunk May 27, 2025
89 of 126 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.0 milestone May 27, 2025
@shimotmk shimotmk deleted the enhancement/refactor-embed-block-control-panel branch May 27, 2025 04:19
@shimotmk
Copy link
Contributor Author

Thanks for the review!

chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
* Embed Block: Refactor setting panel to use ToolsPanel

* fix toggleResponsive

* fix onDeselect

* Update packages/block-library/src/embed/embed-controls.js

Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>

* Update packages/block-library/src/embed/embed-controls.js

Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>

* Update packages/block-library/src/embed/embed-controls.js

Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>

---------

Co-authored-by: shimotmk <shimotomoki@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: carolinan <poena@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Embed Affects the Embed Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor "Settings" panel of Embed block to use ToolsPanel instead of PanelBody
3 participants