quill icon indicating copy to clipboard operation
quill copied to clipboard

When i Paste it is scrolling to the Top

Open Yathish26 opened this issue 1 year ago • 3 comments

When I paste any text or image into the Quill editor, the page scrolls to the top. I'm unsure if this is a bug with Quill or if I'm missing something in my implementation. Here's the code I'm using. Could you help me figure out how to prevent the page from scrolling?

import React, { forwardRef, useImperativeHandle, useRef, useEffect } from 'react';
import ReactQuill, { Quill } from 'react-quill';
import 'react-quill/dist/quill.snow.css';
import ImageResize from 'quill-image-resize-module-react';

Quill.register('modules/imageResize', ImageResize);

const QuillWrapper = forwardRef((props, ref) => {
    const quillRef = useRef(null);

    useImperativeHandle(ref, () => ({
        getEditor: () => quillRef.current.getEditor(),
    }));

    useEffect(() => {
        const quill = quillRef.current.getEditor();
        const root = quill.root;
        root.style.fontSize = '16px';
        root.style.fontFamily = 'Spartan, sans-serif';
    }, []);

    const modules = {
        toolbar: [
            [{ size: ['small', false, 'large', 'huge'] }],
            ['bold', 'italic', 'underline', 'strike'],
            [{ align: [] }],
            [{ list: 'ordered' }, { list: 'bullet' }],
            ['code-block'],   
            ['image', 'link'],
        ],
        imageResize: {
            modules: ['Resize', 'DisplaySize', 'Toolbar'],
        },
        clipboard: {
            matchVisual: false,
        },
    };

    return <ReactQuill ref={quillRef} modules={modules} {...props} />
});

export default QuillWrapper;

Yathish26 avatar Dec 15 '24 06:12 Yathish26

I am facing the same issues. Did you happen to figure out this issue?

malhardhawle avatar Oct 03 '25 15:10 malhardhawle

No then i found out its a Quill Editor Issue itself not working then i changed the library

Yathish26 avatar Oct 06 '25 07:10 Yathish26

Hi @Yathish26 @malhardhawle You can do this to prevent unintended scroll by quill

let lastScroll = window.pageYOffset;

window.onscroll = () => {
    lastScroll = window.pageYOffset;
}

quill.root.addEventListener('paste', (e) => {
    window.scrollTo(0, lastScroll);
});

ghabriel25 avatar Dec 10 '25 07:12 ghabriel25