我正在使用 react-draft-wysiwyg 编辑器,我需要使用选项卡。当我按下制表键时,我希望它留下 4 个空格。为此,我添加了 onTab 事件,但它不起作用。我的代码有什么问题?
请帮忙。
谢谢
代码;
import "draft-js/dist/Draft.css";
import { Editor } from "react-draft-wysiwyg";
import { EditorState, ContentState, convertToRaw, RichUtils, getDefaultKeyBinding } from "draft-js";
import "react-draft-wysiwyg/dist/react-draft-wysiwyg.css";
const NewTac = (props) => {
const [textState, setTextState] = useState(EditorState.createEmpty());
const onHandleKeyBindings = (e) => {
if (e.keyCode === 9) {
setTextState(RichUtils.onTab(e, textState, 4));
return
}
return getDefaultKeyBinding(e);
};
return (
<FormContainer>
<Editor
editorState={textState}
toolbarClassName="toolbarClassName"
wrapperClassName="wrapperClassName"
editorClassName={classes.editorClassName}
onEditorStateChange={onEditorStateChange}
onTab={onHandleKeyBindings}
/>
)}
</FormContainer>
);
};
export default NewTac;