editor icon indicating copy to clipboard operation
editor copied to clipboard

Not able to combine bold and italic like the front page example: what am I missing?

Open j-weave opened this issue 2 years ago • 6 comments

I have a react component of the following nature:

export const RichTextArea = (props: RichTextAreaProps) => {
  const [value, setValue] = useState<string>(props.value || '');

  const handleChange = (updatedValue: string) => {
    setValue(updatedValue);
    props.onChange?.(updatedValue);
  };

  return (
    <MDXEditor
      markdown={value}
      onChange={handleChange}
    />
  );
};

However, when I utilize this plugin, I cannot combine both bold and italic using keyboard shortcuts or any other means. The sequence seems to go like this:

  • Ctrl-B: text turns bold
  • Ctrl-I: text doesn't change
  • Ctrl-B: bold is removed, but now the text is italic (appears to have been stored behind the scenes)
  • Ctrl-I: text is unitalicized

Inspecting the element when bolded gives me something like the following:

<strong class="_bold_16kwi_10 _italic_16kwi_14" data-lexical-text="true">es</strong>

If I do the reverse, I get other odd behavior: Ctrl-I: italicized

<em class="_italic_16kwi_14" data-lexical-text="true">es</em>

Then hit Ctrl-B, the italics disappear and the text turns bold, with the tag now being:

<strong class="_bold_16kwi_10 _italic_16kwi_14" data-lexical-text="true">es</strong>

But neither style shows up in my console to inspect, either, so I'm not sure what the deal is here? Thoughts?

j-weave avatar Jan 11 '24 05:01 j-weave

No, no thoughts. Reproduce it in a sandbox and add the link here, I will take a look, and re-open the issue if necessary.

petyosi avatar Jan 11 '24 06:01 petyosi

@petyosi No problem!

Reproduced here.

  • Go to the "HI there"
  • select the text
  • hit Ctrl-B
  • hit Ctrl-I
  • hit Ctrl-B again

and you'll see the same issue. Clearly this isn't happening on the first form on the front page of the MDXEditor, so what would the difference be here?

j-weave avatar Jan 11 '24 06:01 j-weave

@petyosi I think I've got something here...the classes for the style formatting are all present in the css file attached to your front page:

._bold_16kwi_10 {
    font-weight: 700
}

._italic_16kwi_14 {
    font-style: italic
}

._underline_16kwi_18 {
    text-decoration: underline
}

._strikethrough_16kwi_34 {
    text-decoration: line-through
}

._underlineStrikethrough_16kwi_38 {
    text-decoration: underline line-through
}

._subscript_16kwi_42 {
    font-size: .8em;
    vertical-align: sub!important
}

._superscript_16kwi_47 {
    font-size: .8em;
    vertical-align: super
}

I don't have these styles present in the css in the sandbox example, nor my own code, so this appears to be something created or added into a tailwind css file. Since I don't receive these styles by default when installing the editor, is there something I / other users can be doing to pull this in?

j-weave avatar Jan 11 '24 07:01 j-weave

Without trying to scold you:

  • There are several working examples as repositories for all modern React stacks, all of them mentioned in the docs.
  • The getting started page refers to this line in more than one example:
import '@mdxeditor/editor/style.css'

It's great that you're giving the editor a try, but it's going to be very hard to trial and error your way through the integration without reading the docs. I have no means to support you through chatting in Github issues.

petyosi avatar Jan 11 '24 07:01 petyosi

Hi! Thanks, no worries and I appreciate the aid! Pretty easy for that dependency to slip by, but glad I figured it out - that's a pretty key piece of troubleshooting info! =)

Speaking of trialing and erroring my way through the docs, hope there's some plans to beef up the docs for the APIcore aspect - would help a lot when figuring out how to build our own plugins beyond a trivial one!

Thanks again for your work in making this library, really appreciating it greatly!

j-weave avatar Jan 11 '24 16:01 j-weave

Also submitted https://github.com/mdx-editor/editor/pull/300 to add this note to the docs! Have a great day!

j-weave avatar Jan 11 '24 16:01 j-weave