Skip to content

Commit

Permalink
fix hitting return not creating a new block
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaspiterek committed Feb 20, 2024
1 parent 9643543 commit 4dba394
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/components/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,37 @@ import QuoteBlockSidebar from './Data';
import React from 'react';
import { SidebarPortal } from '@plone/volto/components';
import View from './View';
import config from '@plone/volto/registry';

const Edit = (props) => {
const { data, block, onChangeBlock, selected } = props;
const {
data,
block,
onChangeBlock,
selected,
disableAddBlockOnEnterKey,
onSelectBlock,
onAddBlock,
disableEnter = false,
} = props;

const handleEnterKey = (e, index) => {
const isMultipleSelection = e.shiftKey;
if (e.key === 'Enter' && !disableEnter && !isMultipleSelection) {
if (!disableAddBlockOnEnterKey) {
onSelectBlock(onAddBlock(config.settings.defaultBlockType, index + 1));
}
e.preventDefault();
}
};

return (
<div className="block quote">
<div
className="block quote"
onKeyDown={(e) =>
handleEnterKey(e, props.index, props.id, props.blockNode.current)
}
>
<View {...props} isEditMode />
<SidebarPortal selected={selected}>
<QuoteBlockSidebar
Expand Down

0 comments on commit 4dba394

Please sign in to comment.