Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't autofocus on load #197

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bertie-wheen
Copy link

If the editor has content upon initial load it will gain focus, which can cause unexpected page scrolling.
This is because of using .pasteHTML() (which is just a wrapper around .clipboard.dangerouslyPasteHTML()) - doing it this way fixes the issue with autofocus.
(Incidentally, credit for the fix goes to @jetzhou - see zenoamaro/react-quill#321)

If the editor has content upon initial load it will gain focus, which can cause unexpected page scrolling.
This is because of using `.pasteHTML()` (which is just a wrapper around `.clipboard.dangerouslyPasteHTML()`) - doing it this way fixes the issue with autofocus.
(Incidentally, credit for the fix goes to @jetzhou - see zenoamaro/react-quill#321)
@bertie-wheen
Copy link
Author

Just noticed #194 -- oops! I'll update my package, hopefully the fix by @chrisladams works :)

@bertie-wheen
Copy link
Author

Thankfully #194 means this isn't needed

@bertie-wheen bertie-wheen deleted the patch-1 branch April 11, 2018 20:38
@N-M
Copy link

N-M commented Apr 16, 2018

Seems like this is needed. I added on watch also code that you added

@bertie-wheen bertie-wheen restored the patch-1 branch April 16, 2018 14:01
@bertie-wheen
Copy link
Author

In that case, I've reopened this PR. It might be a nicer way to do it - especially if moved into a method

@bertie-wheen bertie-wheen reopened this Apr 16, 2018
@N-M
Copy link

N-M commented Apr 16, 2018

You will just need to add similar thing in watch


      content(newVal, oldVal) {
        if (this.quill) {
          if (newVal && newVal !== this._content) {
            this._content = newVal
            this.quill.setContents(this.quill.clipboard.convert(newVal))
           } else if(!newVal) {
            this.quill.setText('')
          }
        }
      },
      // Watch content change
      value(newVal, oldVal) {
        if (this.quill) {
          if (newVal && newVal !== this._content) {
            this._content = newVal
            this.quill.setContents(this.quill.clipboard.convert(newVal))
          } else if(!newVal) {
            this.quill.setText('')
          }
        }
      },

@bertie-wheen
Copy link
Author

Indeed, which is why I was mentioning about refactoring it into a method. Can't do it atm as I'm afk but will later if no-one else has

@Cruiser13
Copy link

This should definately be merged.

@bribar
Copy link

bribar commented Aug 31, 2018

Hi guys,

I was running into this same issue. Your fix seems to work, but then causes another issue. When typing the cursor stays at the beginning of the text and spaces don't register. This is my watcher

'taskForm.description': function(newVal) { if (this.$refs.taskDescriptionEditor.quill) { if (newVal && newVal !== this._content) { this._content = newVal; this.$refs.taskDescriptionEditor.quill.setContents(this.$refs.taskDescriptionEditor.quill.clipboard.convert(newVal)); } else if (!newVal) { this.$refs.taskDescriptionEditor.quill.setText(''); } } }

and my component

<quill-editor class="bubble" ref="taskDescriptionEditor" v-model="taskForm.description" :options="editorOption" @blur="onEditorBlur($event)" @focus="onEditorFocus($event)"> </quill-editor>

taskForm is a prop passed form the parent. The focus and blur events just console.log a message.

Any suggestions? If I remove the watcher is goes back to normal with the previous focus issue, but I can type fine.

@Jaspur
Copy link

Jaspur commented Sep 2, 2018

@surmon-china please merge this

@felixledem
Copy link

bump

hariseldon78 added a commit to hariseldon78/vue-quill-editor that referenced this pull request Oct 11, 2020
@bertie-wheen
Copy link
Author

@surmon-china Just noticed this still hasn't been merged. Why? I haven't used the library recently, has it been fixed? (If it has then this can be closed.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants