2
0

feat(editor): ️ Create new item when hitting enter

This commit is contained in:
Baptiste Arnaud
2022-04-04 10:53:03 +02:00
parent f6b518989c
commit 68671433bc
4 changed files with 4 additions and 31 deletions

View File

@ -15,16 +15,10 @@ import { isNotDefined } from 'utils'
type Props = {
item: ButtonItem
indices: ItemIndices
isLastItem: boolean
isMouseOver: boolean
}
export const ButtonNodeContent = ({
item,
indices,
isMouseOver,
isLastItem,
}: Props) => {
export const ButtonNodeContent = ({ item, indices, isMouseOver }: Props) => {
const { deleteItem, updateItem, createItem } = useTypebot()
const [initialContent] = useState(item.content ?? '')
const [itemValue, setItemValue] = useState(item.content ?? 'Click to edit')
@ -44,12 +38,7 @@ export const ButtonNodeContent = ({
const handleKeyPress = (e: React.KeyboardEvent<HTMLDivElement>) => {
if (e.key === 'Escape' && itemValue === 'Click to edit') deleteItem(indices)
if (
e.key === 'Enter' &&
itemValue !== '' &&
isLastItem &&
initialContent === ''
)
if (e.key === 'Enter' && itemValue !== '' && initialContent === '')
handlePlusClick()
}