fix(textarea-control): ace editor input exception (#18146)

This commit is contained in:
Stephen Liu 2022-01-25 23:57:12 +08:00 committed by GitHub
parent 2dd64f9a93
commit 7bb867407a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -63,6 +63,10 @@ export default class TextAreaControl extends React.Component {
this.props.onChange(value);
}
onAreaEditorChange(value) {
this.props.onChange(value);
}
renderEditor(inModal = false) {
const minLines = inModal ? 40 : this.props.minLines || 12;
if (this.props.language) {
@ -76,7 +80,6 @@ export default class TextAreaControl extends React.Component {
style={style}
minLines={minLines}
maxLines={inModal ? 1000 : this.props.maxLines}
onChange={this.props.onChange}
width="100%"
height={`${minLines}em`}
editorProps={{ $blockScrolling: true }}
@ -84,6 +87,7 @@ export default class TextAreaControl extends React.Component {
readOnly={this.props.readOnly}
key={this.props.name}
{...this.props}
onChange={this.onAreaEditorChange.bind(this)}
/>
);
}

View File

@ -54,4 +54,12 @@ describe('TextArea', () => {
expect(wrapper.find(TextArea)).not.toExist();
expect(wrapper.find(TextAreaEditor)).toExist();
});
it('calls onAreaEditorChange when entering in the AceEditor', () => {
const props = { ...defaultProps };
props.language = 'markdown';
wrapper = shallow(<TextAreaControl {...props} />);
wrapper.simulate('change', { target: { value: 'x' } });
expect(defaultProps.onChange.calledWith('x')).toBe(true);
});
});