Skip to content

[color] tag doesn't work in React - Creates element with style string instead of React style object. #293

@ran4na

Description

@ran4na

Steps to reproduce:

  1. Create BBCode string using the color tag: [color=#ff0000]This text should be red[/color]
  2. Attempt to render it in BBob w/ React preset:
const plugins = [presetReact()];

export default function parse_bb(bbcode_input: string): JSX.Element {
  return (<BBCode plugins={plugins}>
    {bbcode_input}
  </BBCode>);
}

...
//someComponent.tsx
parse_bb("[color=#ff0000]This text should be red[/color]");

Outputted error:

Error: The style prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX.

Taking a look at the React BBob tag presets, it looks like the React preset only contains implementations for the b, i, u, and s tags. For color, it falls back to the HTML5 tag preset. This would output the following tag:

<span style="color: #ff0000;">{content}</span>

Which works for HTML5, but React doesn't support inline style strings in JSX. Ideally, tags would be formatted like this:

<span style={{color: "#ff0000"}}>{content}</span>

I tried to create my own color tag, but the documentation and examples don't make it very clear how to supply custom attributes to the created React component, besides its children. How can I do this?

Metadata

Metadata

Assignees

Labels

P1Moderate Issue

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions