Add ability to filter unwanted HTML tags in RichText component #7591
Labels
[Feature] Extensibility
The ability to extend blocks or the editing experience
[Feature] Rich Text
Related to the Rich Text component that allows developers to render a contenteditable
[Type] Enhancement
A suggestion for improvement.
Milestone
Is your feature request related to a problem? Please describe.
We don't have much control over what a user pastes into a RichText. The clipboard might contain HTML tags that are inappropriate for the intended use.
For example, I would want to prevent users from pasting a link (e.g.
<a href="#">foo</a>
) into a RichText intended to be a button.Describe the solution you'd like
Some possibilities:
event.clipboardData.getData( 'text/plain' )
).allowedTags
property on RichText: The consumer could pass it an array of acceptable HTML tagNames, and then RichText would handle the onPaste filtering for us.Describe alternatives you've considered
Use onPaste on a wrapper div: While onCopy can be handled this way, it looks like onPaste must be set on the RichText component itself.
Try doing it onChange: This poses another set of problems, where any kind of string manipulation in an onChange–setState in React breaks CJK IME input, unless we add a workaround with composition event detection. (Related)
For example, doing something like this would make CJK input unusable:
The text was updated successfully, but these errors were encountered: