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

Option in theme.json to (completely) disable typography controls on block level #59730

Closed
lunule opened this issue Mar 9, 2024 · 8 comments
Closed
Labels
[Feature] Typography Font and typography-related issues and PRs [Type] Enhancement A suggestion for improvement.

Comments

@lunule
Copy link

lunule commented Mar 9, 2024

What problem does this address?

Typography controls configuration in theme.json doesn't work properly.

The example I tested is the fontSizes setting, with the following scenario:

  • I have font sizes configured on global level (in the settings section)
  • most of the blocks should have typography controls, but not the core/heading block where I want fix font sizes
    • that can't be changed by the user
    • that are not available in the array of font sizes mentioned above
  • as a result, I need to disable the font size selector for the core/heading block only - but this is currently impossible.

I tested the following variations:

  • "fontSize: false"
  • "fontSizes: false"
  • "fontSize: []"
  • "fontSizes: []"

... in all possible combos, and by applying these combos

  • in the styles section for the core/heading block
  • in the elements section for the h1 element

None of these variations work, it seems that, currently, it's impossible to disable the font size selector on block level if/when the fontSizes array in the settings section is not an empty array (or if it's not set to false).

What is your proposed solution?

The proposed solution is an option in theme.json to completely disable typography controls on block level.

@lunule lunule added the [Type] Enhancement A suggestion for improvement. label Mar 9, 2024
@carolinan
Copy link
Contributor

carolinan commented Mar 10, 2024

Hi
I may be misunderstanding something; did you set it to false under styles.blocks.core/heading? Not under settings.blocks.core/heading?
Styles is used to apply default styles, not to change the available options.

This combination works for me in my test:
Under settings:

		"blocks": {
			"core/heading": {
				"typography": {
					"fontSizes": [],
					"customFontSize": false
				}
			}
		}

I see that the font size is still available as a menu item when I open the "Typography options" from the three dot menu in the block's typography panel, even though the control itself never shows. That does seem like a bug.

@carolinan
Copy link
Contributor

I tested one more thing, for your use case, you probably also want to turn off the font size for the heading elements.
I found that elements is not valid under settings, and I did not find a way to turn the font size off.

It may be a non-issue for scenarios where you are using a classic theme, or you are using a block theme and you want an administrator to have access but not editors. But it would be good to be able to completely disable it.

@lunule
Copy link
Author

lunule commented Mar 10, 2024

Hey @carolinan - thanks for taking a look into this.

did you set it to false under styles.blocks.core/heading? Not under settings.blocks.core/heading?

You're right, and I learned something today. I have, indeed, tested it in styles.blocks.core/heading.
I just checked the settings.blocks.core/heading version, and it works - yay!!

But this is is a quiet 'yay', because we still have

  • the issue that the control can't be disabled by header level, e.g. I might need to enable it for h2s and disable it for h3s, this is still not possible (I just realized that this is the what you describe in your second comment);
  • the bug, with the 'Font Sizes' menu item still being displayed in the Typography dropdown.

(...) But it would be good to be able to completely disable it.

👍I couldn't agree more.

@t-hamano
Copy link
Contributor

the issue that the control can't be disabled by header level, e.g. I might need to enable it for "h2"s and disable it for "h3"s, this is still not possible (I just realized that this is the what you describe in your second comment);

Can't this be achieved with blockEditor.useSetting.before hook? Coincidentally, the Developer Blog has a code example that changes settings depending on the heading level.

Curating the Editor experience with client-side filters – WordPress Developer Blog

See "Restricting settings by block attributes" section

@carolinan
Copy link
Contributor

Thank you for sharing the article.
It is quiet a big gap between these filters and adding a value to theme.json

@lunule
Copy link
Author

lunule commented Mar 11, 2024

Hey @t-hamano , thanks for this share - awesome article, and, actually, the availability of this filter is a solution of the issue described in this feature request.

@carolinan , I need your opinion here 🙂 - while I can use the blockEditor.useSetting.before filter to disable typo controls for specific heading levels, I also agree with your statement ("It is quiet a big gap between these filters and adding a value to theme.json").

What do you think, does the solution described in the artice mean this ticket is to be closed - or let's keep it open with the hope that, one day, support for the requested feature will be added to the theme.json file?

@jordesign jordesign added the [Feature] Typography Font and typography-related issues and PRs label Mar 12, 2024
@t-hamano
Copy link
Contributor

Personally, I think it would be better to close this issue and submit the following two issues:

  • Bug report: The menu appears in the Typography panel even if you completely disable font size at the block level. This may be a problem with other settings as well as font size.
  • Feature request: Allows control of block support depending on heading level via theme.json. I think this means that block support is controlled by the value of the block's attributes.

@carolinan
Copy link
Contributor

Yes, I have opened a separate issue for the first: #59732

@lunule lunule closed this as completed Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Typography Font and typography-related issues and PRs [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

4 participants