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

How to set focus on ckeditor #100

Open
ctwhome opened this issue Nov 19, 2019 · 6 comments
Open

How to set focus on ckeditor #100

ctwhome opened this issue Nov 19, 2019 · 6 comments

Comments

@ctwhome
Copy link

ctwhome commented Nov 19, 2019

Hi, I am not able to set focus on the CKEditor after mounting, do you know how to do it?

<template>
  <vue-ckeditor
    v-model="htmlContent"
    type="classic"
    ref="editor"
  />
</template>

mounted() {
    this.$nextTick(() => this.$refs.editor.focus())
  },

Thanks!

@dangvanthanh
Copy link
Owner

Hi @ctwhome

You can use focus such as

<template>
  <vue-ckeditor
    v-model="htmlContent"
    type="classic"
    ref="editor"
    @focus="onFocus($event)"
  />
</template>

<script>
export default {
   methods: {
     onFocus(event) {
        console.log(event);
     }
   }
}
</script>

@dangvanthanh dangvanthanh self-assigned this Nov 21, 2019
@ctwhome
Copy link
Author

ctwhome commented Nov 25, 2019

Hi @dangvanthanh
thanks for the reply, I am aware of the focus event, what I need to achieve is the other way around, be able to focus "vue-ckeditor" programmatically.

An image is more than a thousand words:
click

@dangvanthanh
Copy link
Owner

Hi @ctwhome

Currently, you can use startupFocus: true in your config to focus when initialize editor. I will improve the options to config focus the editor.

Example

<template>
  <div>
    <button @click.prevent="showEditor">Description</button>
    <vue-ckeditor v-if="isShow" v-model="content" :config="config" ref="editor" />
  </div>
</template>

<script>
import VueCkeditor from 'vue-ckeditor2';

export default {
  name: "HelloWorld",
  components: {
    VueCkeditor
  },
  data() {
    return {
      isShow: false,
      content: '',
      config: {
        toolbar: [
          ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript']
        ],
        height: 300,
        startupFocus: true
      }
    };
  },
  methods: {
    showEditor() {
      this.isShow = !this.isShow;
    }
  }
};
</script>

<style scoped>
</style>

Thank you very much for post issues.

@ctwhome
Copy link
Author

ctwhome commented Nov 26, 2019

oke I will try and let you know, thank YOU for the effort

@ctwhome
Copy link
Author

ctwhome commented Nov 29, 2019

Hi @dangvanthanh
it didn't do the trick. It needs a specific method to focus on the editor.

 <vue-ckeditor
    v-model="htmlContent"
    :config="{ ...editorConfig, placeholder }"
    ......
editorConfig: {
        toolbarLocation: 'bottom', 
        startupFocus: true,
        ignoreEmptyParagraph: true,
       ...
}

@shoungwey
Copy link

add a event @ready="onEditorReady" to
<vue-ckeditor v-if="isShow" v-model="content" :config="config" ref="editor" @ready="onEditorReady" />

and add this method in methods of Vue:
.
.
methods:
{
onEditorReady(editor){
editor.focus();
}
}

that's all.

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

No branches or pull requests

3 participants