From f1a93b7d1e8c52c17b0df227a7aeaa04872ccb76 Mon Sep 17 00:00:00 2001 From: Philip Theobald Date: Sat, 8 Apr 2023 22:07:18 -0500 Subject: [PATCH] feat(vue-quill): add focus method --- docs/content/api/methods.md | 4 ++++ packages/vue-quill/src/components/QuillEditor.ts | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/content/api/methods.md b/docs/content/api/methods.md index 9785274f..7b93de0d 100644 --- a/docs/content/api/methods.md +++ b/docs/content/api/methods.md @@ -53,6 +53,10 @@ We highly recommend to call method when the quill editor ready, use @ready event To import raw HTML from a non-Quill environment. + ## focus() + + Focuses the editor. + ## getText(index, length) - **Parameter:** `index?: number, length?: number` diff --git a/packages/vue-quill/src/components/QuillEditor.ts b/packages/vue-quill/src/components/QuillEditor.ts index aab9ab6b..9d8ce266 100644 --- a/packages/vue-quill/src/components/QuillEditor.ts +++ b/packages/vue-quill/src/components/QuillEditor.ts @@ -289,7 +289,7 @@ export const QuillEditor = defineComponent({ const getQuill = (): Quill => { if (quill) return quill else - throw `The quill editor hasn't been instantiated yet, + throw `The quill editor hasn't been instantiated yet, make sure to call this method when the editor ready or use v-on:ready="onReady(quill)" event instead.` } @@ -340,6 +340,10 @@ export const QuillEditor = defineComponent({ if (delta) quill?.setContents(delta, source) } + const focus = () => { + quill?.focus() + } + const reinit = () => { nextTick(() => { if (!ctx.slots.toolbar && quill) @@ -380,6 +384,7 @@ export const QuillEditor = defineComponent({ getHTML, setHTML, pasteHTML, + focus, getText, setText, reinit,