Skip to content

Commit e451ea6

Browse files
committed
Use uncontrolled textarea for InstructionsEditor
1 parent 9d52744 commit e451ea6

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

src/components/InstructionsEditor.jsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import {t} from 'i18next';
44
import bindAll from 'lodash/bindAll';
55

66
export default class InstructionsEditor extends React.Component {
7-
constructor({instructions}) {
7+
constructor() {
88
super();
9-
this.state = {instructions};
109
bindAll(this, '_handleCancelEditing', '_handleSaveChanges', '_ref');
1110
}
1211

@@ -15,12 +14,12 @@ export default class InstructionsEditor extends React.Component {
1514
}
1615

1716
_handleSaveChanges() {
18-
const newValue = this.editor.innerText.trim();
17+
const newValue = this.editor.value.trim();
1918
this.props.onSaveChanges(this.props.projectKey, newValue);
2019
}
2120

22-
_ref(preElement) {
23-
this.editor = preElement;
21+
_ref(editorElement) {
22+
this.editor = editorElement;
2423
}
2524

2625
render() {
@@ -40,13 +39,11 @@ export default class InstructionsEditor extends React.Component {
4039
{t('workspace.components.instructions.cancel')}
4140
</button>
4241
</div>
43-
<pre
44-
contentEditable
42+
<textarea
4543
className="instructions-editor__input"
44+
defaultValue={this.props.instructions}
4645
ref={this._ref}
47-
>
48-
{this.state.instructions}
49-
</pre>
46+
/>
5047
</div>
5148
);
5249
}

src/css/application.css

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
--size-rounded-corners: 0.2em;
8484
--size-top-bar: 4em;
8585
--size-top-bar-menu-button: 2.8em;
86+
--size-instructions-menu-padding: calc(28px + 1rem);
8687
--box-shadow: 0 0 0.1em 0 rgba(0, 0, 0, 0.5);
8788
--font-size-menu: 1.7vh;
8889
}
@@ -351,16 +352,22 @@ body {
351352
/** @define instructions-editor */
352353

353354
.instructions-editor {
354-
height: 100%;
355-
padding-top: calc(28px + 1rem);
355+
height: calc(100% - var(--size-instructions-menu-padding) - 1rem);
356+
padding-top: var(--size-instructions-menu-padding);
356357
}
357358

358359
.instructions-editor__input {
359-
height: 100%;
360+
width: 100%;
361+
height: calc(100% - 1rem);
360362
margin: 0;
363+
font-family: monospace;
364+
font-size: 1rem;
365+
background-color: transparent;
366+
border: 0;
361367
outline: 0;
362368
word-wrap: break-word;
363369
white-space: pre-wrap;
370+
resize: none;
364371
}
365372

366373
.instructions-editor__menu {
@@ -369,7 +376,6 @@ body {
369376
right: 0;
370377
left: 0;
371378
padding: 0.5rem;
372-
margin-bottom: 100%;
373379
text-align: right;
374380
background-color: var(--color-light-gray);
375381
}

0 commit comments

Comments
 (0)