react-draft-wysiwyg icon indicating copy to clipboard operation
react-draft-wysiwyg copied to clipboard

Text alignment is saved but it is not reflected on the editor

Open mastepanoski opened this issue 6 years ago • 11 comments

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.

mastepanoski avatar Nov 08 '18 20:11 mastepanoski

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.

rickstricker avatar Nov 12 '18 17:11 rickstricker

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 avatar Dec 07 '18 17:12 imjared

@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 :)

jpuri avatar Dec 19 '18 07:12 jpuri

Can confirm the css patch fixes the problem

franleplant avatar May 07 '19 18:05 franleplant

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

bbeck10 avatar May 10 '19 13:05 bbeck10

any updates here?

IlkhamGaysin avatar Jun 11 '20 16:06 IlkhamGaysin

@jpuri

IlkhamGaysin avatar Jun 11 '20 16:06 IlkhamGaysin

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

Spyron1234 avatar Jan 11 '21 10:01 Spyron1234

@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 avatar Mar 16 '21 18:03 f-CJ

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

lomeat avatar May 05 '21 11:05 lomeat

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.

abenoit-reeliant avatar Jun 02 '21 13:06 abenoit-reeliant

I needed to add following css rules:

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

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

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

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

With those rules it works as expected.

crudobaker avatar Nov 23 '22 18:11 crudobaker