admin管理员组文章数量:1125714
I want to use tiptap to implement an editable inline label, but I found that the cursor cannot focuson the inside of the label. It always automatically jumps to the end of the label.
<script type="module">
const EditableTag = Node.create({
name: 'editableTag',
group: 'inline',
inline: true,
content: '(inline | text)*',
// ...
renderHTML({ HTMLAttributes }) {
return ['span', { 'data-type': 'editable-tag', class: 'editable-tag' }, 0]
},
addKeyboardShortcuts() {
return {
Enter: () => true,
Backspace: ({editor}) => {
const { selection } = editor.state
console.log('Backspace', editor.state);
return true;
}
}
},
addNodeView() {
return ({ node, getPos, editor }) => {
const wrapper = document.createElement('span')
wrapper.setAttribute('data-type', 'editable-tag')
// create contentDOM
const contentDOM = document.createElement('span')
contentDOM.textContent = node.attrs.value
contentDOM.classList.add('editable-tag-content')
wrapper.appendChild(contentDOM)
return {
dom: wrapper,
contentDOM, // set contentDOM as editable area
}
}
},
addCommands() {
// ...
}
});
</script>
本文标签:
版权声明:本文标题:javascript - How to use tiptap to implement an editable inline label? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736662097a1946464.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论