Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit adcaab4

Browse files
committed
Update quill docs
1 parent 770e49a commit adcaab4

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

docs/rich-text/quill.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,19 @@ You will then need to utilize the `config` slot on the component to define a Jav
181181
toolbarHandlers: {
182182
variables: function (value) {
183183
value = `[[ ${value} ]]`;
184-
const quill = instance.__quill;
185-
const cursorPosition = quill.getSelection().index;
186-
quill.insertText(cursorPosition, value);
187-
quill.setSelection(cursorPosition + value.length);
184+
const cursorPosition = this.quill.getSelection().index;
185+
this.quill.insertText(cursorPosition, value);
186+
this.quill.setSelection(cursorPosition + value.length);
188187
},
189188
},
190189
</x-slot:config>
191190
</x-quill>
192191
```
193192

193+
> {note} It is important to not use arrow functions for the toolbar handlers, as they will not have access to the `this` context of Quill.
194+
> For the example above, it is important to reference the quill instance via `this.quill`, otherwise you may get unexpected results when
195+
> inserting text.
196+
194197
This example will provide a custom dropdown menu with two options, and when each one is clicked on, it will insert the text of the option into the editor at the current cursor position of the user. Your work is not done yet, however. Quill editor uses CSS styling to render the text into the toolbar buttons, so you will need to add some styles to your stylesheet:
195198

196199
```css
@@ -216,7 +219,7 @@ slot to do this. The config slot is inside a JavaScript function that returns an
216219

217220
| variable | description |
218221
| --- | --- |
219-
| `instance` | The Alpine data instance for the quill component. To access to the quill editor instance, you can do so via `instance.__quill` |
222+
| `instance` | The Alpine data instance for the quill component |
220223
| `quillOptions` | An object containing the options generated by the component |
221224

222225
For a complete list of quill configuration options, see [Quill Configuration](https://quilljs.com/docs/configuration/).

docs/upgrade.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,10 @@ Here is an example of how you could define a handler for a custom toolbar button
8484
```html
8585
<x-slot:config>
8686
toolbarHandlers: {
87-
variables: function(value) {
88-
const quill = instance.__quill;
89-
const cursorPosition = quill.getSelection().index;
90-
quill.insertText(cursorPosition, value);
91-
quill.setSelection(cursorPosition +value.length);
87+
variables: function (value) {
88+
const cursorPosition = this.quill.getSelection().index;
89+
this.quill.insertText(cursorPosition, value);
90+
this.quill.setSelection(cursorPosition +value.length);
9291
},
9392
},
9493
</x-slot:config>

0 commit comments

Comments
 (0)