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

pasteHandler ignores FormattingControls prop #18637

Closed
leorospo opened this issue Nov 20, 2019 · 4 comments
Closed

pasteHandler ignores FormattingControls prop #18637

leorospo opened this issue Nov 20, 2019 · 4 comments
Labels
[Feature] Paste [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Type] Enhancement A suggestion for improvement.

Comments

@leorospo
Copy link

Describe the bug
Setting the formattingControl prop in a RichTextComponent to ['italic'] will limit the formatting options in said block to only show the italic button.
The problem is that when you copy / paste some text from a word document it will keep the orignal formattimg even if it is not allowed in the component. Moreover because of the lack of the other formatting buttons the user is not able to manually remove the unwanted/unallowed formatting styles.

To reproduce
Steps to reproduce the behavior:

  1. Register a Block with a RichText component and formattingControls prop set to italic
            <RichText
                tagName="h4"
                value={text}
                formattingControls={['italic']}
                onChange={(content) => setAttributes({ text: content })}
            />
  1. Copy / paste some text containing various combination of bold and italics
  2. Try to remove the unallowed bold formatting.

Expected behavior
On paste the unallowed formatting styles are ignored and treated like normal text.

Desktop (please complete the following information):

  • OS: Win10
  • Browser Firefox Developer Edition

Might reference
Overview: Writing Flow #16280
https://github.com/WordPress/gutenberg/labels/%5BFeature%5D%20Raw%20Handling

@jorgefilipecosta jorgefilipecosta added [Feature] Paste [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Type] Bug An existing feature does not function as intended labels Nov 21, 2019
@ellatrix
Copy link
Member

I'm not sure if this is to be expected or not. The formattingControls props controls the formatting controls. It doesn't disallow certain formatting in the RichText instance. You can still go to the HTML view and add anything you like there. I'm open to limiting paste in this case though.

@ellatrix ellatrix added [Type] Enhancement A suggestion for improvement. and removed [Type] Bug An existing feature does not function as intended labels Dec 10, 2019
@leorospo
Copy link
Author

The behaviour persist with th allowedFormats prop

@mirka
Copy link
Member

mirka commented Apr 16, 2021

Related: #7591

@Mamaduka
Copy link
Member

I'm going to close the issue.

Why

  • The allowedFormats prop works as designed. The setting controls format options displayed for a RichText instance, not the paste behavior.
  • The __unstablePastePlainText can change the latter.

@Mamaduka Mamaduka closed this as not planned Won't fix, can't repro, duplicate, stale Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Paste [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

5 participants