Skip to content

Commit

Permalink
Prevent adding new line on enter
Browse files Browse the repository at this point in the history
  • Loading branch information
anselm94 committed Mar 12, 2020
1 parent 4dcafe3 commit 100ea9b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions web/src/components/todo/ContentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ export default function ({ notes, setNotes, isEditMode }) {
updatedNoteItems.splice(index, 1);
setNotes(updatedNoteItems);
};
const onKeyPressed = (index, keyCode) => {
if (keyCode === 13) { // Enter pressed, create a new row item
const onKeyPressed = (index, event) => {
if (event.keyCode === 13) { // Enter pressed, create a new row item
event.preventDefault();
var updatedNoteItems = Object.assign([], notes);
updatedNoteItems = updatedNoteItems.filter(note => note.text !== "")
updatedNoteItems.splice(index + 1, 0, { text: "", isCompleted: false });
Expand Down Expand Up @@ -164,7 +165,7 @@ function ContentListItem({
value={text}
placeholder={isEditMode ? "List Item" : ""}
onChange={event => onTextChange(index, event.target.value)}
onKeyDown={event => onKeyPressed(index, event.keyCode)}
onKeyDown={event => onKeyPressed(index, event)}
onFocus={() => setFocussed(true)}
onBlur={() => setFocussed(false)}
autoFocus={isEmpty}
Expand Down

0 comments on commit 100ea9b

Please sign in to comment.