fix(extension/bubble-menu): 🐛 fix bubble menu and floating menu being available when editor not editable (#3195)
This commit is contained in:
@@ -2,7 +2,7 @@ import './styles.scss'
|
||||
|
||||
import { BubbleMenu, EditorContent, useEditor } from '@tiptap/react'
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
import React from 'react'
|
||||
import React, { useEffect } from 'react'
|
||||
|
||||
export default () => {
|
||||
const editor = useEditor({
|
||||
@@ -16,8 +16,20 @@ export default () => {
|
||||
`,
|
||||
})
|
||||
|
||||
const [isEditable, setIsEditable] = React.useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
if (editor) {
|
||||
editor.setEditable(isEditable)
|
||||
}
|
||||
}, [isEditable, editor])
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
<input type="checkbox" checked={isEditable} onChange={() => setIsEditable(!isEditable)} />
|
||||
Editable
|
||||
</div>
|
||||
{editor && <BubbleMenu editor={editor} tippyOptions={{ duration: 100 }}>
|
||||
<button
|
||||
onClick={() => editor.chain().focus().toggleBold().run()}
|
||||
|
||||
@@ -3,3 +3,7 @@
|
||||
margin-top: 0.75em;
|
||||
}
|
||||
}
|
||||
|
||||
input[type="checkbox"] {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
<template>
|
||||
<div>
|
||||
<div>
|
||||
<input type="checkbox" :checked="isEditable" @change="() => isEditable = !isEditable">
|
||||
Editable
|
||||
</div>
|
||||
<bubble-menu :editor="editor" :tippy-options="{ duration: 100 }" v-if="editor">
|
||||
<button @click="editor.chain().focus().toggleBold().run()" :class="{ 'is-active': editor.isActive('bold') }">
|
||||
bold
|
||||
@@ -28,9 +32,16 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
editor: null,
|
||||
isEditable: true,
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
isEditable(value) {
|
||||
this.editor.setEditable(value)
|
||||
},
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.editor = new Editor({
|
||||
extensions: [
|
||||
@@ -57,4 +68,8 @@ export default {
|
||||
margin-top: 0.75em;
|
||||
}
|
||||
}
|
||||
|
||||
input[type="checkbox"] {
|
||||
margin-right: 4px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -2,7 +2,7 @@ import './styles.scss'
|
||||
|
||||
import { EditorContent, FloatingMenu, useEditor } from '@tiptap/react'
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
import React from 'react'
|
||||
import React, { useEffect } from 'react'
|
||||
|
||||
export default () => {
|
||||
const editor = useEditor({
|
||||
@@ -17,8 +17,20 @@ export default () => {
|
||||
`,
|
||||
})
|
||||
|
||||
const [isEditable, setIsEditable] = React.useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
if (editor) {
|
||||
editor.setEditable(isEditable)
|
||||
}
|
||||
}, [isEditable, editor])
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
<input type="checkbox" checked={isEditable} onChange={() => setIsEditable(!isEditable)} />
|
||||
Editable
|
||||
</div>
|
||||
{editor && <FloatingMenu editor={editor} tippyOptions={{ duration: 100 }}>
|
||||
<button
|
||||
onClick={() => editor.chain().focus().toggleHeading({ level: 1 }).run()}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
<template>
|
||||
<div>
|
||||
<div>
|
||||
<input type="checkbox" :checked="isEditable" @change="() => isEditable = !isEditable">
|
||||
Editable
|
||||
</div>
|
||||
<floating-menu :editor="editor" :tippy-options="{ duration: 100 }" v-if="editor">
|
||||
<button @click="editor.chain().focus().toggleHeading({ level: 1 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 1 }) }">
|
||||
H1
|
||||
@@ -28,9 +32,16 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
editor: null,
|
||||
isEditable: true,
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
isEditable(value) {
|
||||
this.editor.setEditable(value)
|
||||
},
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.editor = new Editor({
|
||||
extensions: [
|
||||
|
||||
Reference in New Issue
Block a user