React-draft-wysiwyg: Text alignment is saved but it is not reflected on the editor

Created on 8 Nov 2018  路  11Comments  路  Source: jpuri/react-draft-wysiwyg

screenshot_2018-11-08 react draft wysiwyg

Example: If you take a paragraph from here lipsum, paste it react-draft-wysiwyg site, and then you select all text and press center (or justify or right), the content is not centered in the editor.
I used it in a project and when I generated HTML from the content, the paragraph has the style "text-align: center;" but the editor does not show the alignment.

Most helpful comment

@imjared 's solution looks correct

.rdw-center-aligned-block * {
    text-align: center !important;
}

is fixing it. I will soon put this fix in code itself. Thanks :)

This fix doesn't seem to work when alignment is equals to justify or right, I had to add this extra rule:

.public-DraftStyleDefault-ltr {
  text-align: inherit !important;
}

All 11 comments

Here's a little more info about this issue. After playing with this a bit, the problem appears to be related to line wrapping. If a piece of text is short enough not to wrap, then it is centering fine. Adding words to the sentence to make it wrap, will cause the centered text to stop wrapping in the editor. You can also reproduce it by simply resizing the browser such that the centered piece of text will wrap, and again the text is now no longer being centered in the editor. Resize back to one line and the text again centers.

What I'm seeing is that the actual HTML output is fine but the CSS needs a tweak. Adding this rule _seems_ to fix it but I'm not familiar enough with the overall CSS to say if this would have unintended effects.

.rdw-center-aligned-block > * {
  text-align: center;
}

Actual view:
image

Expected view:
image

@imjared 's solution looks correct

.rdw-center-aligned-block * {
    text-align: center !important;
}

is fixing it. I will soon put this fix in code itself. Thanks :)

Can confirm the css patch fixes the problem

I created a PR with this css update - https://github.com/jpuri/react-draft-wysiwyg/pull/827

any updates here?

@jpuri

Hi All, is there any fix for the mentioned issue available?

@imjared 's solution looks correct

.rdw-center-aligned-block * {
    text-align: center !important;
}

is fixing it. I will soon put this fix in code itself. Thanks :)

This fix doesn't seem to work when alignment is equals to justify or right, I had to add this extra rule:

.public-DraftStyleDefault-ltr {
  text-align: inherit !important;
}

@f-CJ Thank you! You saved my working time :)
All work as expected

Doesn't seem to work for justified text on Firefox, unless we add a CSS to change white-space to 'normal' for instance.

But with that CSS change, when we go to the end of the content on Firefox and type in a space, the cursor goes back to the beginning of the text, which makes the editor unsable for typing text.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FriOne picture FriOne  路  3Comments

volkandkaya picture volkandkaya  路  3Comments

regisBafutwabo picture regisBafutwabo  路  3Comments

DiegoGallegos4 picture DiegoGallegos4  路  4Comments

Fireprufe15 picture Fireprufe15  路  4Comments