• Say I’m building my own block and I’m using the RichText component. How can I have bold option being preselected when using it?

    So that whenever I start using my block, the text I’m inputting already has the bold option toggled?

Viewing 4 replies - 1 through 4 (of 4 total)
  • I don’t have an answer for you, but you are not likely to find it in this forum.
    You might try StackExchange.

    A similar thing was happening in Twenty Twenty One for the quote block. See https://github.com/WordPress/twentytwentyone/issues/762
    but I think instead of making the editor control match the style (or putting the <strong> tag, they simply changed the CSS, so it’s not quite what you are asking.
    It seems like there’s an API for RichText, but I know nothing more than that.

    Thread Starter Denis ?oljom

    (@dingo_d)

    Yeah, I scoured the GB code, but couldn’t find any info on how this could be achieved. I tried adding <strong> tags but that messed the output (strong would be parsed and repeated with encoded < and >). In the end, I just left it regular, and whenever the user needs to have bold heading they need to do it themselves (which is a bad UX imo).

    I don’t often ask things on SE (or WPSE) because people are not responding, and I didn’t want to open another issue on GB, because I thought it was something I overlooked in the docs or something. But I think I’ll have to…

    Thanks for the help ????

    I think there should be a distinction between HTML and styles in RichText.
    Normally, in a paragraph, when you select some text and click on B, does it put strong tags or a class?
    Does the parser work correctly when pasting markup?

    In your custom block, are you trying to control the bold with the same method as RichText does (tags or CSS)?

    Thread Starter Denis ?oljom

    (@dingo_d)

    In both cases, I think it wraps the content with the strong tag.

    I’m actually using the RichText component as a part of my own implementation of dynamic blocks (I’m not using the JS save method).

    I used the onChange method to store the strong tag in the editor part (markup), but it ended up adding 3 or 4 tags around it. Which was odd to me.

    In the end, I gave up, and just left it as is (not bolded)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to toggle bold option in RichText component?’ is closed to new replies.