React-draft-wysiwyg: Autoscroll on new line

Created on 18 May 2020  路  7Comments  路  Source: jpuri/react-draft-wysiwyg

How can I make editor's input to scroll down automatically on new line input? Like in example 6 at https://jpuri.github.io/react-draft-wysiwyg/#/demo. Now scroll stays on top and text cursor hides when goes below bottom border.

All 7 comments

I have the same problem :(

I have the same problem :(

Who solved this problem?

Has anyone solved this issue?

When I press enter, it will start typing on a new line that is hidden, but once i type 2 characters, it suddenly jumps down so the text is visible again. Very odd behavior.

Has anyone solved this issue?

When I press enter, it will start typing on a new line that is hidden, but once i type 2 characters, it suddenly jumps down so the text is visible again. Very odd behavior.

it seems not

I solved this problem by attaching some hooks to the editor, and scrolling to the bottom of the div when the number of lines change.
````javascript
const [lines, setLines] = useState(0);
const editorRef = useRef(null);

const handleEditorChange = function(e) {
const prevLines = lines;

if(prevLines !== e.blocks.length) {
  setLines(e.blocks.length);
}

};

useEffect(() => {
const scrollDiv = editorRef.current.querySelector(".wysiwyg-editor");
scrollDiv.scrollTop = scrollDiv.scrollHeight;
}, [lines]);

return(

);
````

@jtrost It is interesting decision. So i tried your variant. But class '.wysiwyg-editor' is not exist. I have only these:
image
I tried also '.rdw-editor-wrapper' and '.DraftEditor-root' and others. But all they have EditorState with _immutable state. So i can't figure how to scroll down.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MaDejing picture MaDejing  路  3Comments

jpuri picture jpuri  路  4Comments

ananddodia picture ananddodia  路  4Comments

kcabading picture kcabading  路  3Comments

gyarasu picture gyarasu  路  4Comments