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

textAlign is not restored

Open sylvainbx opened this issue 7 years ago • 17 comments

When initializing the Editor with some previously saved content, eg:

{"blocks":[
  {"key":"78mel",
  "text":"Lorem ipsum duis vulputate erat vel tortor ornare lobortis. In tempus aliquet elit nec porttitor.",
  "type":"unstyled",
  "depth":0,
  "inlineStyleRanges":[],
  "entityRanges":[],
  "data":{"textAlign":"center"}}
],"entityMap":{}}

The text alignment is not restored. All other properties are restored correctly (bold, italic, list ...), but textAlign (here center but possibly right or justify) are not restored.

Here's the full code of my component: https://gist.github.com/sylvainbx/e281f0596617b6119559f05388318e7d

I'm using react-draft-wysiwyg 1.9.0 and draft-js 0.10.0. Any suggestions are welcome :)

sylvainbx avatar Apr 11 '17 07:04 sylvainbx

@sylvainbx : thanks for reporting the issue, I will check this.

jpuri avatar Apr 16 '17 07:04 jpuri

Also, @sylvainbx : are you facing this issue when you display content in HTML ? That I fixed in last version already.

jpuri avatar Apr 16 '17 07:04 jpuri

Hi, thanks for your answer. I've just upgraded react-draft-wysiwyg from 1.9.0 to 1.9.4 but sadly, this does not solve the issue.

I don't know what you mean by "display content in HTML". I'm displaying some draft raw content (like the initial example I gave) in the <Editor />, using convertFromRaw and createWithContent.

sylvainbx avatar Apr 20 '17 12:04 sylvainbx

This should be fixed in latest version, can you plz check: [email protected].

jpuri avatar Apr 29 '17 17:04 jpuri

Hi! I have the same problem, and im using the version [email protected]

cesaracortes avatar May 02 '17 03:05 cesaracortes

I will check this again. Thanks for reporting @cesaracortes

jpuri avatar May 02 '17 03:05 jpuri

Hi, I've upgraded to [email protected], but I still have the issue. Moreover, now I'm having the following error in the console:

warning.js?85a7:36 Warning: Failed prop type: Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types
    in e (created by TextEditor)
    in TextEditor (created by ProjectId)
    ...

sylvainbx avatar May 02 '17 08:05 sylvainbx

Same for me.

When trying to load :

const contentBlocks = convertFromHTML('<p style="text-align:right;">right aligned</p>')
const editorState = EditorState.createWithContent(ContentState.createFromBlockArray(contentBlocks))

style="text-align:right;" seems to be stripped out.

editorState is:

 {
        entityMap: {},
        blockMap: {
          '89ct4': {
            key: '89ct4',
            type: 'unstyled',
            text: 'right aligned',
            characterList: [
              { style: [], entity: null },
              { style: [], entity: null },
              { style: [], entity: null },
              { style: [], entity: null },
              { style: [], entity: null },
              { style: [], entity: null },
              { style: [], entity: null },
              { style: [], entity: null },
              { style: [], entity: null },
              { style: [], entity: null },
              { style: [], entity: null },
              { style: [], entity: null },
              { style: [], entity: null },
            ],
            depth: 0,
            data: {},
          },
        },
        selectionBefore: {
          anchorKey: '89ct4',
          anchorOffset: 0,
          focusKey: '89ct4',
          focusOffset: 0,
          isBackward: false,
          hasFocus: false,
        },
        selectionAfter: {
          anchorKey: '89ct4',
          anchorOffset: 0,
          focusKey: '89ct4',
          focusOffset: 0,
          isBackward: false,
          hasFocus: false,
        },
 }

I guess data: {} should be: data: {'text-align': 'right'} after convertFromHTML. Maybe i'm doing sth wrong?

I'm using

  • draft-js 0.10.1
  • draftjs-to-html 0.7.2
  • react-draft-wysiwyg 1.9.8

adashst avatar May 13 '17 17:05 adashst

Any update on this ?

sylvainbx avatar May 23 '17 07:05 sylvainbx

Me too, get a trouble with text-align when convertFromHtml. Any help?

htactive avatar Jun 21 '17 07:06 htactive

I am running into the same issue, any update for this?

ed-zm avatar Sep 24 '18 20:09 ed-zm

Any updates? I'm having this problem :(

lucasmonstrox avatar Oct 03 '18 12:10 lucasmonstrox

I was having the same issue using the default convertFromHTML (from Draft.js), but after switching to the recommended package: https://github.com/jpuri/html-to-draftjs and using htmlToDraft instead solved my issue.

Slooowpoke avatar Feb 19 '19 15:02 Slooowpoke

This is working well here in storybook: https://github.com/jpuri/react-draft-wysiwyg/blob/master/stories/ConvertFromRawDraftContent/index.js#L19

jpuri avatar Mar 02 '19 18:03 jpuri

i want to send these editorState content send to as a email to Gmail. How to handle this editorstate content using Node JS

shanmuga2414 avatar Mar 20 '19 06:03 shanmuga2414

Same problem here when rendering editorState the text-align & font-family is striping away :

const contentDataState =
        ContentState.createFromBlockArray(convertFromHTML("<h3 style="text-align:center;"><span style="font-family: Tahoma;"><strong>This A Sample Text</strong></span></h3>"));
const [editorState, seteditorState] = React.useState(EditorState.createWithContent(contentDataState));

I'm using: "react-draft-wysiwyg": "^1.14.7" "draft-js": "^0.11.7", "draftjs-to-html": "^0.9.1",

suvomoy avatar Jan 07 '22 15:01 suvomoy

Same issue here:

<p style="text-align:right;"><strong>It’s different, but we like different.</strong></p>

const blocksFromHtml = convertFromHTML(defaultValue);
        const contentState = ContentState.createFromBlockArray(
          blocksFromHtml.contentBlocks,
          blocksFromHtml.entityMap
        );
        const newEditorState = EditorState.createWithContent(contentState);
        setEditorState(newEditorState);

...

return (<Editor
        toolbarHidden
        readOnly={true}
        editorState={editorState}
        onEditorStateChange={onEditorStateChange}
      />);
    "react-draft-wysiwyg": "^1.15.0",
 "draft-js": "^0.11.7",
    "draftjs-to-html": "^0.9.1",

SaundersB avatar Feb 04 '24 15:02 SaundersB