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

RichText: add withoutInteractiveFormatting prop #14542

Merged
merged 7 commits into from
Jul 24, 2019

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Mar 20, 2019

Description

Fixes #15212 (comment).
Fixes #14528.
Fixes #15858.

Adds a withoutInteractiveFormatting prop to RichText. We currently have a use case where we'd like to remove the link button (and any other interactive elements) from blocks such as button, file, and search, as it would create invalid HTML.

Also deprecates formattingControls and introduces allowedFormats (similar to allowedBlocks). Example: [ 'core/bold' ].

How has this been tested?

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@ellatrix ellatrix added [Type] Bug An existing feature does not function as intended [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable labels Mar 28, 2019
@ellatrix ellatrix force-pushed the try/rich-text-disallow-formats branch from 1986755 to f959e91 Compare April 4, 2019 07:38
@ellatrix ellatrix requested a review from aduth as a code owner April 4, 2019 07:38
@aduth

This comment has been minimized.

Copy link
Member

@noisysocks noisysocks left a comment

Choose a reason for hiding this comment

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

Flipping this API makes total sense to me! 👍

I think we need to make the new prop more backwards compatible. Other than that, this is great.

packages/block-editor/src/components/rich-text/index.js Outdated Show resolved Hide resolved
packages/block-library/src/file/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/file/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/search/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/search/edit.js Outdated Show resolved Hide resolved
@ellatrix ellatrix force-pushed the try/rich-text-disallow-formats branch from f959e91 to e674f20 Compare June 26, 2019 11:58
@ellatrix ellatrix added the [Type] Regression Related to a regression in the latest release label Jun 26, 2019
@ellatrix ellatrix added this to the Gutenberg 6.1 milestone Jun 26, 2019
@ellatrix ellatrix changed the title RichText: add disallowFormats prop RichText: add withoutInteractiveFormatting prop Jun 26, 2019
@ellatrix ellatrix dismissed noisysocks’s stale review June 26, 2019 12:11

I'm not sure if there's a way to make it fully backwards compatible.

@noisysocks

This comment has been minimized.

@ellatrix

This comment has been minimized.

@ellatrix
Copy link
Member Author

@chrisvanpatten Sure, it makes sense to allow it if you know what you're doing. I'll add something like allowedFormats (just like allowedBlocks) where you can fine tune the controls. I'll deprecate formattingControls and make it backwards compatible (even though it's been a bit broken for a while).

@chrisvanpatten
Copy link
Contributor

@chrisvanpatten Sure, it makes sense to allow it if you know what you're doing. I'll add something like allowedFormats (just like allowedBlocks) where you can fine tune the controls. I'll deprecate formattingControls and make it backwards compatible (even though it's been a bit broken for a while).

@ellatrix you da best! That would be amaaaaazing. Thank you!!!

@ellatrix ellatrix requested a review from epiqueras July 20, 2019 12:33
@ellatrix ellatrix added the Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code label Jul 20, 2019
@ellatrix ellatrix requested a review from chrisvanpatten July 20, 2019 12:38
@ellatrix
Copy link
Member Author

@chrisvanpatten @epiqueras I added a allowedFormats prop now. This would also remove the dropdown if there's no formats.

@ellatrix
Copy link
Member Author

We will also need this PR for footnotes. The footnotes format will be disabled in instances that enabled withoutInteractiveFormatting (e.g. button block).

@ellatrix
Copy link
Member Author

@mcsf Might be useful for you title block. :)

@obenland obenland added Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code and removed Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code labels Jul 22, 2019
@obenland
Copy link
Member

Got here through the "Good First Review" label and thought it was added by accident or a long time ago, given the size of this PR. My bad, I put it back :)

Copy link
Member

@noisysocks noisysocks left a comment

Choose a reason for hiding this comment

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

Looks great, and I like this API! 👍

We ought to add a note to block-editor/CHANGELOG.md which describes this change.

While testing this I noticed a bug where, in the Search block, if you move focus from the label field to the placeholder field, the formatting controls don't go away. This bug exists on master, though, so not a blocker.

search


if ( formattingControls ) {
deprecated( 'wp.blockEditor.RichText formattingControls prop', {
version: 'the future',
Copy link
Member

Choose a reason for hiding this comment

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

Unless there's a specific version that we're planning to remove this, I think it's best to omit the version option.

Suggested change
version: 'the future',

Copy link
Member Author

Choose a reason for hiding this comment

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

I did what the docs recommended:

* deprecated( 'Eating meat', {
* version: 'the future',
* alternative: 'vegetables',
* plugin: 'the earth',
* hint: 'You may find it beneficial to transition gradually.',
* } );

return;
}

if ( formattingControls ) {
Copy link
Member

Choose a reason for hiding this comment

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

This if isn't necessary if we move the deprecated() call to be after the if ( allowedFormats ) { ... } below.

Copy link
Member Author

Choose a reason for hiding this comment

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

What if you use both?

packages/block-editor/src/components/rich-text/index.js Outdated Show resolved Hide resolved
@ellatrix
Copy link
Member Author

While testing this I noticed a bug where, in the Search block, if you move focus from the label field to the placeholder field, the formatting controls don't go away. This bug exists on master, though, so not a blocker.

That only happens when switching between a RichText instance and input or textarea, right? I know that this happens, we keep some selection state to work around losing it when you press a button outside the editable area. I'll try to fix it at some point.

@ellatrix ellatrix force-pushed the try/rich-text-disallow-formats branch from 05791a9 to d959422 Compare July 24, 2019 09:21
@ellatrix ellatrix merged commit 4ef9b7e into master Jul 24, 2019
@ellatrix ellatrix deleted the try/rich-text-disallow-formats branch July 24, 2019 10:00
@youknowriad
Copy link
Contributor

Does this fix #12439 too?

@ktmn
Copy link

ktmn commented Sep 6, 2019

Also deprecates formattingControls and introduces allowedFormats

I've been using formattingControls={[]} to hide the controls from certain RichText's, but it's still possible for advanced users to Ctrl + I to make something italic or Ctrl + K to add a link inline, or use a third party format (if it has a hotkey) etc.

With the allowedFormats prop I can't do that and the toolbar is cluttered with the format controls which aren't really needed 99% of the time but I'd like to have available.

For example, I have a custom button block that already uses bold text. I don't really want to display the Bold format on the toolbar, so I should disallow it? For that I have to add every single other format to allowedFormats? What about third party formats?
But wait, the theme allows to customize whether the button uses bold text or not. Now I should make allowing of that format dynamic? I'd rather it just be available under Ctrl + B but not be cluttering up the toolbar.

I'd like to allow all formats, but just hide the controls. Maybe only keep the (More )Rich Text Controls button on the toolbar and nothing else:
image

Could there be a withoutFormattingControls prop or compactFormattingControls or something like that?


We currently have a use case where we'd like to remove the link button (and any other interactive elements) from blocks such as button, file, and search, as it would create invalid HTML.

Then why add a whitelist prop and not a blacklist prop? Doesn't this lock out 3rd party formats that may or may not have worked and been useful?

@talldan
Copy link
Contributor

talldan commented Sep 6, 2019

@ktmn I'd recommend either commenting on an existing open issue that is on the same topic or creating a new issue (if there isn't one already).

It's really easy to miss comments on already merged PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code [Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release
Projects
None yet
10 participants