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

unregisterFormatType at the Block/Component level #16246

Open
AlchemyUnited opened this issue Jun 22, 2019 · 5 comments
Open

unregisterFormatType at the Block/Component level #16246

AlchemyUnited opened this issue Jun 22, 2019 · 5 comments
Labels
[Package] Rich text /packages/rich-text [Type] Enhancement A suggestion for improvement.

Comments

@AlchemyUnited
Copy link

Is your feature request related to a problem? Please describe.
Ultimately, I want to limit "user error"/"human error" as much as possible. So, for example, RichText formats types of 'code' or 'inline image' for a heading aren't appropriate. They are however suitable for say paragraph. Counting on telling a user not to do X or Y is ultimately a UX destine for doom :)

Unless, I'm doing it all wrong, unregisterFormatType dose let me remove formats. Great. The bad news is, those are global, and can not be applied selectively. That is, there's no way (I've found, so it could be me) to do unregisterFormatType at the block / RT component level.

https://github.com/WordPress/gutenberg/blob/master/packages/rich-text/src/unregister-format-type.js

Describe the solution you'd like
Ultimately, maybe what would be best would be to make RichText's formattingControls=[] more robust. At the moment, it's limited to bold, italic, and link. [1] And there's no way (that's I've found) via the RT component's props to do anything about the items in the More menu.

Describe alternatives you've considered
I did try using formattingControls and unregisterFormatType together. That is, remove bold with unregisterFormatType and then selectively add it back with formattingControls . No go. Didn't work for me. But, again, perhaps there's a way to do this that's unpublished and/or I just haven't found it yet.

Also
[1] The README / docs also lists strikethrough as valid with RT's formattingControls but strikethrough isn't effected. It should be removed from the doc (or there's a bug).

[2] When I dumped the format types

 const oldFormat = select( 'core/rich-text' );
 console.log(oldFormat);
 console.log(oldFormat.getFormatTypes());

This is what I got:

0: {name: "core/bold", title: "Bold", tagName: "strong", className: null, edit: ƒ}
1: {name: "core/code", title: "Code", tagName: "code", className: null, edit: ƒ}
2: {name: "core/image", title: "Image", keywords: Array(2), object: true, tagName: "img", …}

3: {name: "core/italic", title: "Italic", tagName: "em", className: null, edit: ƒ}
4: {name: "core/link", title: "Link", tagName: "a", className: null, attributes: {…}, …}
5: {name: "core/strikethrough", title: "Strikethrough", tagName: "s", className: null, edit: ƒ}
6: {name: "core/underline", title: "Underline", tagName: "span", className: null, attributes: {…}, …}

What I find odd is that core/underline can't be added / influenced with formattingControls, but it also doesn't show up in the "More Rich Text Controls" menu either. So core/underline is registered yet never shows up. Is that right? Or a bug?

p.s. It would also be super nice if we could control the "More Rich Text Controls" tool tip message. That is, instead of "More Rich Text Controls" it would be a more focused and sensible UX to say "More Heading Controls" or "More Heading Settings". A plain Joe / plain Jane user has not idea what Rich Text is, nor should they. Proper language, while subtle, would improve the UX.

@AlchemyUnited AlchemyUnited changed the title unregisterFormatType at the Block level unregisterFormatType at the Block/Component level Jun 22, 2019
@swissspidy swissspidy added [Package] Rich text /packages/rich-text [Type] Enhancement A suggestion for improvement. labels Jun 25, 2019
@paaljoachim
Copy link
Contributor

Hey @AlchemyUnited

Thank you for creating the issue!
Is this still valid?

@ptbello
Copy link

ptbello commented Jan 19, 2021

@paaljoachim it is for me, absolutely.
At the moment I resort to dirty tricks to remove formatting options where inappropriate - It would be great to be able to invoke a clean unregister at the block level.
A lot of the problems devs are having boil down to not being able to disable certain features when they conflict with a project's design system - see for example the comments on #19796, along the same lines.

@AlchemyUnited
Copy link
Author

@ptbello - Agreed. Without support for design systems, Gutenburg will never fulfill its destiny. The underlying technology is great. Unfortunately, it often feels out of touch with real-world use.

@paaljoachim - To answer your question, I have no idea if this is still valid. I don't think I've gone back to it since opening the ticket. Sorry.

@paaljoachim
Copy link
Contributor

Well one good place it bring attention to this issue is during a Wednesday Core Editor chat.
An example would be to add a comment here and it can be brought up for the Open Floor.
https://make.wordpress.org/core/2021/01/19/editor-chat-agenda-20th-january-2021/

@gwwar
Copy link
Contributor

gwwar commented Feb 24, 2021

So core/underline is registered yet never shows up. Is that right? Or a bug?

Underline is usable as a keyboard shortcut, but not a visible format. This is because underline and justify was removed in WP 4.7 see https://core.trac.wordpress.org/ticket/27159. I personally don't agree, but the project reasons noted the following for why: " It introduces a potentially bad user experience issue: readers confusing the underline text with a link. Underlined text is broadly interpreted as web links."

If you'd like a visible underline button, it should be possible to register a new format type. See https://developer.wordpress.org/block-editor/tutorials/format-api/

@AlchemyUnited did you have any luck with allowedFormats? It's a whitelist, so usage looks a bit like the following:

https://github.com/WordPress/gutenberg/pull/19507/files#diff-161a9737e181e56e07148b7eee4795f129aa821f73993a276cf1fd9c17941b70R158-R163

It would also be super nice if we could control the "More Rich Text Controls" tool tip message. That is, instead of "More Rich Text Controls" it would be a more focused and sensible UX to say "More Heading Controls" or "More Heading Settings".

We can maybe split this one out into its own issue to see what folks think. Copy suggestions are welcome ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Rich text /packages/rich-text [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

5 participants