【问题标题】:cant remove list dot in draft js on backspace react-draft-wysiwyg无法删除退格键上的草稿 js 中的列表点 react-draft-wysiwyg
【发布时间】:2022-10-05 16:44:46
【问题描述】:

我使用draftJS在我的项目中编辑文本,目前我面临这样一个问题,如果你在一个空的编辑器中包含一个带有点或数字的列表,那么它不能用退格键删除 my editor

```<Editor
    editorState={description}
    toolbarStyle={editorStyles.toolbarStyle}
    editorStyle={editorStyles.editorStyle}
    onEditorStateChange={onChangeDescription}
    placeholder={placeholder}
    toolbar={toolbar}
  />```

    标签: javascript reactjs draftjs react-draft-wysiwyg


    【解决方案1】:

    我只是研究draft.js。您可以通过RichUtils.handleKeyCommand 处理键盘命令。 下面的代码是我创建了一个函数handleKeyCommandEn。然后它可以处理退格来删除列表

    import { EditorState, convertToRaw, ContentState,RichUtils } from "draft-js";
    
    ...
    
        const handleKeyCommandEn = (command) => {
          const newState = RichUtils.handleKeyCommand(editorStateEn, command);
          if (newState) {
            setEditorStateEn(newState);
            return true;
          }
          return false;
        };
    
    ...
    
                    <Editor
                        editorState={editorStateEn}
                        wrapperClassName="demo-wrapper"
                        editorClassName="demo-editor"
                        onEditorStateChange={setEditorStateEn}
                        toolbar={{
                          options:['inline','blockType', 'fontSize', 'fontFamily', 'list', 'textAlign', 'remove', 'history'],
                          textAlign: { inDropdown: true },
                          inline :{options:['bold', 'italic', 'underline', 'strikethrough','superscript','subscript']}
                        }}
                        localization={{
                          locale: 'en',
                        }}
                        stripPastedStyles={true} // disable paste style
                        handleKeyCommand={handleKeyCommandEn}
                        placeholder={intl.formatMessage({ id: "editorPlaceholder" })}
                      />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-06
      • 1970-01-01
      • 2021-11-21
      • 2019-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多