【发布时间】:2020-08-26 23:36:36
【问题描述】:
如何在 React 中关闭 quill.js 中的拼写检查?
我发现this GitHub page 显示了如何在普通 JavaScript 中禁用 quill 的拼写检查器:
const quill = new Quill('#editor-container')
quill.root.setAttribute('spellcheck', false)
但是,我看不到如何使用 React 组件来实现它。
我的 React 组件(实际上是 Preact):
import { h, FunctionalComponent } from 'preact';
import './contentEditor.scss';
import Quill from 'react-quill';
import 'react-quill/dist/quill.snow.css';
interface ContentEditorProps {
content: string | undefined;
onChange(value: string): void;
}
const modules = {
toolbar: [
[{ header: [1, 2, 3, 4, false] }],
['bold', 'italic', 'underline', 'blockquote'],
[{ color: [] }],
[{ align: [] }],
[{ list: 'ordered' }, { list: 'bullet' }],
[{ indent: '-1' }, { indent: '+1' }],
['link', 'image'],
],
};
const formats = [
'header',
'bold',
'color',
'italic',
'underline',
'strike',
'blockquote',
'list',
'bullet',
'align',
'indent',
'link',
'image',
];
export const ContentEditor: FunctionalComponent<ContentEditorProps> = ({
content,
onChange,
}) => {
return (
<Quill
theme='snow'
value={content}
onChange={onChange}
modules={modules}
formats={formats}
/>
);
};
【问题讨论】:
-
从未使用过,但由于
quill.root.setAttribute()设置了元素属性,请尝试将其添加到<Quill spellcheck={false}...的道具中 -
这是个好主意——事实上,我认为它会起作用......不幸的是,它没有。不过,谢谢你的想法。
标签: javascript reactjs quill preact