Skip to content

Commit

Permalink
homework/HomeworkModal: make description textbox enter behavior consi…
Browse files Browse the repository at this point in the history
…stent (enter = new line, shift+enter or ctrl+enter = submit)
  • Loading branch information
thatoddmailbox committed Nov 23, 2023
1 parent 1aec2ab commit 528f475
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions app/homework/HomeworkModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,20 @@ export default function HomeworkModal(props) {
</Modal>;
}

const keydown = (shiftEnter) => {
return (e) => {
if (e.keyCode == 13 && !(e.shiftKey && shiftEnter)) {
save();
e.preventDefault();
return false;
}
};
const keydown = (e) => {
if (e.keyCode == 13) {
save();
e.preventDefault();
return false;
}
};

const descriptionKeydown = (e) => {
if (e.keyCode == 13 && (e.shiftKey || e.ctrlKey)) {
save();
e.preventDefault();
return false;
}
};

return <Modal title={(isNew ? "Add homework" : "Edit homework")} openModal={props.openModal} class="homeworkModal">
Expand All @@ -114,7 +120,7 @@ export default function HomeworkModal(props) {
<div class="homeworkModalBody">

<div class="homeworkModalNameWrapper">
<PrefixedEdit class="homeworkModalName" placeholder="Name" inputRef={nameInputRef} value={name} onKeyDown={keydown(false)} onInput={(e) => setName(e.target.value)} />
<PrefixedEdit class="homeworkModalName" placeholder="Name" inputRef={nameInputRef} value={name} onKeyDown={keydown} onInput={(e) => setName(e.target.value)} />
</div>

<div class="doneCheckbox">
Expand All @@ -129,7 +135,7 @@ export default function HomeworkModal(props) {
<ClassPicker value={classId} change={setClassId} classes={props.classes} />
</div>

<textarea class="form-control homeworkModalDesc" placeholder="Description" onInput={(e) => setDesc(e.target.value)} onKeyDown={keydown(true)} value={desc}></textarea>
<textarea class="form-control homeworkModalDesc" placeholder="Description" onInput={(e) => setDesc(e.target.value)} onKeyDown={descriptionKeydown} value={desc}></textarea>
</div>
</div>
<div class="modal-footer">
Expand Down

0 comments on commit 528f475

Please sign in to comment.