Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions packages/inline-dropdown/configure/src/inline-dropdown-toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class RespAreaToolbar extends React.Component {
choices: PropTypes.array,
onAddChoice: PropTypes.func.isRequired,
onCheck: PropTypes.func,
editorCallback: PropTypes.func,
onRemoveChoice: PropTypes.func.isRequired,
onSelectChoice: PropTypes.func.isRequired,
onToolbarDone: PropTypes.func.isRequired,
Expand Down Expand Up @@ -283,11 +284,10 @@ class RespAreaToolbar extends React.Component {

onKeyDown = (event) => {
if (event.key === 'Enter') {
const html = event.target?.innerHTML || '';
const html = this.editorRef.getHTML() || '';

this.onDone(html);
this.preventDone = true;
this.focusInput();

// Cancelling event
return true;
Expand Down Expand Up @@ -321,16 +321,6 @@ class RespAreaToolbar extends React.Component {
this.clickedInside = true;
};

focusInput = () => {
// we need to focus the input so that math is saved even without pressing the green checkmark
const slateEditorRef = this.editorRef && this.editorRef.rootRef && this.editorRef.rootRef.slateEditor;
const inputRef = slateEditorRef && slateEditorRef.editorRef && slateEditorRef.editorRef.element;

if (inputRef) {
inputRef.focus();
}
};

render() {
const {
choices,
Expand All @@ -356,9 +346,10 @@ class RespAreaToolbar extends React.Component {
>
<ItemBuilder>
<RespArea
ref={(ref) => {
editorRef={(ref) => {
if (ref) {
this.editorRef = ref;
this.props.editorCallback?.(ref);
}
}}
autoFocus={true}
Expand Down Expand Up @@ -407,7 +398,6 @@ class RespAreaToolbar extends React.Component {
mathMlOptions={mathMlOptions}
/>
<AddButton
onMouseDown={() => this.focusInput()}
onClick={() => this.onAddChoice()}
size="small"
aria-label="Add"
Expand Down
3 changes: 2 additions & 1 deletion packages/inline-dropdown/configure/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,9 @@ export class Main extends React.Component {
respAreaToolbar: (node, editor, onToolbarDone) => {
const { respAreaChoices } = this.state;

return () => (
return props => (
<InlineDropdownToolbar
{...props}
onAddChoice={this.onAddChoice}
onCheck={this.onCheck}
onRemoveChoice={(index) => this.onRemoveChoice(node.attrs.index, index)}
Expand Down
Loading