Skip to content

Commit 4b5cf9f

Browse files
authored
Merge pull request #2943 from pie-framework/fix/PD-5603-PD-5604-PD-5605
fix: editor instance handling on the response area PD-5603-PD-5603-PD5-605
2 parents 92338bf + 7478bad commit 4b5cf9f

2 files changed

Lines changed: 6 additions & 15 deletions

File tree

packages/inline-dropdown/configure/src/inline-dropdown-toolbar.jsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class RespAreaToolbar extends React.Component {
177177
choices: PropTypes.array,
178178
onAddChoice: PropTypes.func.isRequired,
179179
onCheck: PropTypes.func,
180+
editorCallback: PropTypes.func,
180181
onRemoveChoice: PropTypes.func.isRequired,
181182
onSelectChoice: PropTypes.func.isRequired,
182183
onToolbarDone: PropTypes.func.isRequired,
@@ -283,11 +284,10 @@ class RespAreaToolbar extends React.Component {
283284

284285
onKeyDown = (event) => {
285286
if (event.key === 'Enter') {
286-
const html = event.target?.innerHTML || '';
287+
const html = this.editorRef.getHTML() || '';
287288

288289
this.onDone(html);
289290
this.preventDone = true;
290-
this.focusInput();
291291

292292
// Cancelling event
293293
return true;
@@ -321,16 +321,6 @@ class RespAreaToolbar extends React.Component {
321321
this.clickedInside = true;
322322
};
323323

324-
focusInput = () => {
325-
// we need to focus the input so that math is saved even without pressing the green checkmark
326-
const slateEditorRef = this.editorRef && this.editorRef.rootRef && this.editorRef.rootRef.slateEditor;
327-
const inputRef = slateEditorRef && slateEditorRef.editorRef && slateEditorRef.editorRef.element;
328-
329-
if (inputRef) {
330-
inputRef.focus();
331-
}
332-
};
333-
334324
render() {
335325
const {
336326
choices,
@@ -356,9 +346,10 @@ class RespAreaToolbar extends React.Component {
356346
>
357347
<ItemBuilder>
358348
<RespArea
359-
ref={(ref) => {
349+
editorRef={(ref) => {
360350
if (ref) {
361351
this.editorRef = ref;
352+
this.props.editorCallback?.(ref);
362353
}
363354
}}
364355
autoFocus={true}
@@ -407,7 +398,6 @@ class RespAreaToolbar extends React.Component {
407398
mathMlOptions={mathMlOptions}
408399
/>
409400
<AddButton
410-
onMouseDown={() => this.focusInput()}
411401
onClick={() => this.onAddChoice()}
412402
size="small"
413403
aria-label="Add"

packages/inline-dropdown/configure/src/main.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,9 @@ export class Main extends React.Component {
523523
respAreaToolbar: (node, editor, onToolbarDone) => {
524524
const { respAreaChoices } = this.state;
525525

526-
return () => (
526+
return props => (
527527
<InlineDropdownToolbar
528+
{...props}
528529
onAddChoice={this.onAddChoice}
529530
onCheck={this.onCheck}
530531
onRemoveChoice={(index) => this.onRemoveChoice(node.attrs.index, index)}

0 commit comments

Comments
 (0)