add autoFocus option, close #149
This commit is contained in:
@@ -69,6 +69,7 @@ useBuiltInExtensions
|
|||||||
| --- | :---: | :---: | --- |
|
| --- | :---: | :---: | --- |
|
||||||
| `content` | `Object\|String` | `null` | The editor state object used by Prosemirror. You can also pass HTML to the `content` slot. When used both, the `content` slot will be ignored. |
|
| `content` | `Object\|String` | `null` | The editor state object used by Prosemirror. You can also pass HTML to the `content` slot. When used both, the `content` slot will be ignored. |
|
||||||
| `editable` | `Boolean` | `true` | When set to `false` the editor is read-only. |
|
| `editable` | `Boolean` | `true` | When set to `false` the editor is read-only. |
|
||||||
|
| `autoFocus` | `Boolean` | `false` | Focus the editor on init. |
|
||||||
| `extensions` | `Array` | `[]` | A list of extensions used, by the editor. This can be `Nodes`, `Marks` or `Plugins`. |
|
| `extensions` | `Array` | `[]` | A list of extensions used, by the editor. This can be `Nodes`, `Marks` or `Plugins`. |
|
||||||
| `useBuiltInExtensions` | `Boolean` | `true` | By default tiptap adds a `Doc`, `Paragraph` and `Text` node to the Prosemirror schema. |
|
| `useBuiltInExtensions` | `Boolean` | `true` | By default tiptap adds a `Doc`, `Paragraph` and `Text` node to the Prosemirror schema. |
|
||||||
| `dropCursor` | `Object` | `{}` | Config for `prosemirror-dropcursor`. |
|
| `dropCursor` | `Object` | `{}` | Config for `prosemirror-dropcursor`. |
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export default class Editor {
|
|||||||
constructor(options = {}) {
|
constructor(options = {}) {
|
||||||
this.defaultOptions = {
|
this.defaultOptions = {
|
||||||
editable: true,
|
editable: true,
|
||||||
|
autoFocus: false,
|
||||||
extensions: [],
|
extensions: [],
|
||||||
content: '',
|
content: '',
|
||||||
emptyDocument: {
|
emptyDocument: {
|
||||||
@@ -52,6 +53,13 @@ export default class Editor {
|
|||||||
this.view = this.createView()
|
this.view = this.createView()
|
||||||
this.commands = this.createCommands()
|
this.commands = this.createCommands()
|
||||||
this.setActiveNodesAndMarks()
|
this.setActiveNodesAndMarks()
|
||||||
|
|
||||||
|
if (this.options.autoFocus) {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.focus()
|
||||||
|
}, 10)
|
||||||
|
}
|
||||||
|
|
||||||
this.options.onInit({
|
this.options.onInit({
|
||||||
view: this.view,
|
view: this.view,
|
||||||
state: this.state,
|
state: this.state,
|
||||||
|
|||||||
Reference in New Issue
Block a user