Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keydown listener for Enter key to submit text #104

Merged
merged 1 commit into from
Aug 1, 2024
Merged
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
Add keydown listener for Enter key to submit text
- Enhanced useEffect to handle Enter key press
- Submit text and exit edit mode when Enter key is pressed
- Maintain proper cleanup of event listeners
LourdesRsdp committed Aug 1, 2024
commit 899da6e0a57ebeb97315daa4f8f83f54bb8343d6
10 changes: 10 additions & 0 deletions src/common/components/inline-edit/inline-edit.tsx
Original file line number Diff line number Diff line change
@@ -38,14 +38,24 @@ export const EditableComponent: React.FC<Props> = props => {
}
};

const handleKeyDown = (event: KeyboardEvent) => {
if (isEditing && event.key === 'Enter') {
setIsEditing(false);
onTextSubmit(editText);
}
};

if (isEditing) {
document.addEventListener('mousedown', handleClickOutside);
document.addEventListener('keydown', handleKeyDown);
} else {
document.removeEventListener('mousedown', handleClickOutside);
document.addEventListener('keydown', handleKeyDown);
}

return () => {
document.removeEventListener('mousedown', handleClickOutside);
document.addEventListener('keydown', handleKeyDown);
};
}, [isEditing, editText]);