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

Provide a way to remove/modify text alignment for core blocks #24616

Open
jakewhiteley opened this issue Aug 18, 2020 · 9 comments
Open

Provide a way to remove/modify text alignment for core blocks #24616

jakewhiteley opened this issue Aug 18, 2020 · 9 comments
Labels
Customization Issues related to Phase 2: Customization efforts [Feature] Block API API that allows to express the block paradigm. [Type] Enhancement A suggestion for improvement.

Comments

@jakewhiteley
Copy link

Is your feature request related to a problem? Please describe.
As someone who uses WordPress to provide websites for clients, I need to be able to restrict the type of content a user can add via Gutenberg. This could be due to design reasons, enforcing a style guide for editors, or simply because the theme does not support alignment.

This is directly related to the rationale behind #15160 .

Describe the solution you'd like
Either include alignment in the upcoming experiemental-theme.json, or provide a robust (and documented) way to modify the alignment control on all core blocks - without having to deregister a core block, and register a customised version as a replacement.

It should allow a developer to specify which alignments are supported, or completely disable alignment.

the blocks.registerBlockType feels like a good candidate as it already can be used to disable alignment for some core blocks.

Describe alternatives you've considered
I tried the following:

window.wp.hooks.addFilter('blocks.registerBlockType', 'my-theme/hide-alignment', function(settings, name) {
	return Object.assign({}, settings, {
		supports: Object.assign({}, settings.supports, {align: false})
	})

	return settings
})

But this only removes alignment controls on blocks like core/embed, it does not remove text alignment on core/heading or core/paragraph.

@ellatrix
Copy link
Member

Maybe we could tie this in with the current theme support for wide and full alignment? Cc @mtias @jasmussen

@jasmussen
Copy link
Contributor

Whether it's through the wide and full alignment support, or whether it's tied into the global styles feature registration, the use case seems fair enough. But given that it's conceptually not just about alignments, but presumably the argument could also be made for any other stylistic option, I wonder if there's a way to indeed bake the control right into the global styles work. @nosolosw any thoughts?

@mtias
Copy link
Member

mtias commented Aug 25, 2020

Agreed it should probably be handled or explored through the theme.json which provides a more ergonomic way of dealing with specific block attributes rather than ad hoc theme supports.

@mtias mtias added [Feature] Block API API that allows to express the block paradigm. [Type] Enhancement A suggestion for improvement. Customization Issues related to Phase 2: Customization efforts labels Aug 25, 2020
@gchtr
Copy link
Contributor

gchtr commented Jun 17, 2021

In the use case that I have, I need to remove text alignment for paragraph blocks for a certain post type only, and not globally. Would that be possible with theme.json?

@mtias
Copy link
Member

mtias commented Jun 22, 2021

theme.json can be filterable so it can be tweaked in a given editing context. cc @nosolosw for clarification

@oandregal
Copy link
Member

Details about filtering possibilities can be found here with links to specific places Gutenberg uses them. TLDR: for block editor settings, it suffices to hook into the block editor settings filter (related changes in 5.8).

@oandregal oandregal mentioned this issue Jun 22, 2021
82 tasks
@oandregal
Copy link
Member

I've also added this issue to the backlog section at #20331 so it's easier to find when it comes to deciding the next steps for block supports and what options should be available through theme.json.

@stephensabatini
Copy link

Bumping this as I'm running into a point where I need to disable text alignment on core blocks (all, with exceptions)... the theme.json approach honestly sounds like the dream in this scenario. I've not been able to find a way to accomplish this so far. Is there a temporary workaround or way to disable this via JS for each (or all)? I followed the link provided in this thread, but it appears the links referenced in it are 404ing, so I might be missing some context there. Appreciate any insight you have regarding this. Thank you!

@Leksat
Copy link

Leksat commented May 15, 2023

AFAIK the only way at the moment is CSS

.components-toolbar-group button[aria-label='Align'] {
  display: none;
}

Not that nice, but works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Customization Issues related to Phase 2: Customization efforts [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

8 participants