0

In my React solution I am using a custom component called RichText. The problem with this component is, that one of the styles for h2 element has different font-weight as I would need to. I am trying to override default style of this custom component, but due to the fact that this property is set as !important I am unable to do so (as order of custom component style takes precedense over my import). Please refer to image below:

enter image description here

I have tried the following things to make sure, my CSS class will be loaded later (which should place it hierarchically above the css of custom component):

  • Change order of imports at the top of my component (tried to make it first, tried to make it last; nothing worked)
  • tried to use lifecycle events (componentDidMount) and dynamically import css then
  • tried to load css with timer (e.g. wait 2 seconds and then import() class)
  • used :global identifier in my scss class

Yet nothing has changed the order of this class. Am I missing something or what do I need to do in order to make sure it will be loaded as expected?

1 Answer 1

0

As I test,if we want to change the text in onChange property,the control will not change the style.
As a workaround,you could try to change the default Bold function font-weight.

Test code:

    .richtext strong{
        font-weight: 300!important;
      }

<RichText className={styles.richtext}
          onChange={(text)=>this.onChange(text)}
/>
private onChange = (newText: string) => {
    
  return newText;
}

Test result: enter image description here Or you could try to ask for further help in pnp control github.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes this is a feasible option, however in my case users have very long rich texts (combination of various styles and elements) thus post processing would be quite painful...yet I agree that this would definitely work :) Thank you for your answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.