Reactjs React-Redux draft.js-对空文本区域进行验证会导致奇怪的光标定位
我目前正在我的一个React项目中使用,我一直在使用我创建的自定义组件,除了一些redux验证之外,我还在使用draftjs 问题是,我进行了验证,如果用户正在键入,然后从textarea中删除所有文本,提示redux验证并显示“必需”文本,但是由于我有一些代码,我遇到了一个奇怪的问题,光标突出显示了一个字母,或者当我按backspace/delete时,光标被推到了textarea的第一个位置,这导致我的textarea无法使用 以下是我的组件:Reactjs React-Redux draft.js-对空文本区域进行验证会导致奇怪的光标定位,reactjs,redux-form,draftjs,Reactjs,Redux Form,Draftjs,我目前正在我的一个React项目中使用,我一直在使用我创建的自定义组件,除了一些redux验证之外,我还在使用draftjs 问题是,我进行了验证,如果用户正在键入,然后从textarea中删除所有文本,提示redux验证并显示“必需”文本,但是由于我有一些代码,我遇到了一个奇怪的问题,光标突出显示了一个字母,或者当我按backspace/delete时,光标被推到了textarea的第一个位置,这导致我的textarea无法使用 以下是我的组件: import React from 'reac
import React from 'react';
import { RadioButton, RadioButtonGroup } from 'material-ui/RadioButton';
import { Editor, EditorState, convertFromRaw } from 'draft-js';
class TextareaRequired extends React.Component { react/prefer-stateless-function
componentWillMount() {
if (this.props.input.value === '') {
if (this.props.data) {
this.props.input.onChange(EditorState.createWithContent(convertFromRaw(JSON.parse(this.props.data))));
}
}
}
changeTextArea(editorState) {
if (this.props.input.onChange) {
this.props.input.onChange(editorState);
}
// If the editorState is empty; we change the input value to null to enable invalid state for redux
if (!editorState.getCurrentContent().hasText()) {
this.props.input.onChange(null);
}
}
render() {
const { meta } = this.props;
return (
<div>
<div className="grey-border">
<Editor
editorState={this.props.input.value || EditorState.createEmpty()}
onChange={::this.changeTextArea} // eslint-disable-line
/>
</div>
{meta.touched && meta.error && <div className="form-error">{meta.error}</div>}
</div>
);
}
}
export default TextareaRequired;
有没有人使用Draft.js足够了解这里的潜在问题
提前谢谢
if (!editorState.getCurrentContent().hasText()) {
this.props.input.onChange(null);
}