Skip to content

Commit d7bae5b

Browse files
committed
fix: readonly
1 parent d2ba03f commit d7bae5b

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

src/components/MarkdownText/MarkdownText.jsx

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,7 @@ import { markdownToHTML } from '../../helpers/markdownToState'
77
class MarkdownText extends Component {
88
constructor (props) {
99
super(props)
10-
this.state = {
11-
isChanged: false
12-
}
13-
this.blurTheField = this.blurTheField.bind(this)
14-
this.updateDescriptionThrottled = this.updateDescription.bind(this)
15-
// this.updateDescriptionThrottled = _.throttle(this.updateDescription.bind(this), 10000) // 10s
16-
}
17-
18-
blurTheField () {
19-
const { onChange } = this.props
20-
onChange(this.easymde.value())
10+
this.updateDescription = this.updateDescription.bind(this)
2111
}
2212

2313
updateDescription () {
@@ -30,25 +20,18 @@ class MarkdownText extends Component {
3020
if (!readOnly) {
3121
this.easymde = new EasyMDE({ element: this.refs.textarea, initialValue: value })
3222
this.easymde.codemirror.on('change', () => {
33-
this.setState({ isChanged: true })
34-
this.updateDescriptionThrottled(this.easymde.value())
35-
})
36-
this.easymde.codemirror.on('blur', () => {
37-
if (this.state.isChanged) {
38-
this.setState({ isChanged: false })
39-
this.blurTheField()
40-
}
23+
this.updateDescription()
4124
})
4225
} else {
43-
this.ref.current.innerHTML = value ? markdownToHTML(value) : ''
26+
this.refs.textarea.innerHTML = value ? markdownToHTML(value) : ''
4427
}
4528
}
4629

4730
render () {
4831
const { readOnly, placeholder } = this.props
4932
return (<div className={styles.editor}>
5033
{readOnly ? (
51-
<div ref="textarea" />
34+
<div ref="textarea" className="EasyMDEContainer-readonly"/>
5235
) : (
5336
<textarea
5437
ref="textarea"

src/components/MarkdownText/MarkdownText.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
display: flex;
1010

1111
:global {
12-
.EasyMDEContainer {
12+
.EasyMDEContainer-readonly {
13+
border: 1px solid #aaaaab;
14+
border-radius: 4px;
15+
padding: 0 10px;
16+
}
17+
18+
.EasyMDEContainer, .EasyMDEContainer-readonly {
1319
display: flex;
1420
width: 100%;
1521
flex-direction: column;

0 commit comments

Comments
 (0)