首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >React Quill不可编辑嵌入

React Quill不可编辑嵌入
EN

Stack Overflow用户
提问于 2021-01-04 06:49:23
回答 1查看 603关注 0票数 1

用反应笔。我想要添加一个不可编辑的文本块,我可以创建污点,但是如果我尝试向它添加一个contenteditable=false属性,它就不能工作。我的代码如下

代码语言:javascript
运行
复制
import ReactQuill from 'react-quill';
import './App.scss';
import 'react-quill/dist/quill.snow.css';

import { useState, useRef } from 'react';

const Quill = ReactQuill.Quill;
const BlockEmbed = Quill.import('blots/embed');


class Mention extends BlockEmbed {
  static create(value) {
    let node = super.create(value);
    node.innerText = value;
    // node.contenteditable = false;
    node.setAttribute("contenteditable", false);
    return node;
  }
  static value(node) {
    return node.childNodes[0].textContent;
  }
}

Mention.blotName = 'label';
Mention.tagName = 'SPAN';
Mention.className = 'ql-label';
Quill.register(Mention);



function App() {
  const [value, setValue] = useState('');
  const thisEditor = useRef(null);

  const inserMention = (thisEditor) => {
    const editor = thisEditor.getEditor();
    let range = editor.getSelection();
    let position = range ? range.index : 0;
    editor.insertEmbed(position, 'label');
  }
  return (
    <div className="container bg-crow-green bg-gradient px-0">

      <div className='mt-4 border rounded'>
        <ReactQuill ref={thisEditor} theme='snow' value={value} onChange={setValue} />
        <button type="button" className="btn mt-4 btn-danger w-25" onClick={() => inserMention(thisEditor.current)}>Insert</button>
      </div>
    </div >
  );
}

export default App;

单击“插入”按钮,创建一个新的嵌入并将其添加到编辑器,但它是可编辑的,但我不想要。另一个问题是,我想引用新添加的嵌入,然后也更改它的值,我可以使用Parment.find()来完成这个任务,然后使用格式,但是我不知道如何在react中这样做。

EN

回答 1

Stack Overflow用户

发布于 2022-10-28 02:43:43

尝试使用camcelCase属性。

代码语言:javascript
运行
复制
 node.setAttribute("contentEditable", false);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65558682

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档