Skip to content

Commit

Permalink
fix: fix escape button behavior in DescriptionEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
esasova committed Aug 19, 2024
1 parent 6facdb4 commit b923038
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ const DescriptionEditor = (props) => {
[onChange, value]
);

const cancelEdition = useCallback((event) => {
event.stopPropagation();
event.preventDefault();
setIsEditing(false);
}, []);

const editIcon = useMemo(() => {
if (readOnly || isEditing || !isHovered) return null;
return <EditIcon data-cy="edit-description" className={classes.editIcon} onClick={startEdition}></EditIcon>;
Expand All @@ -70,7 +76,7 @@ const DescriptionEditor = (props) => {
onChange={(event) => setDescriptionText(event.target.value)}
onKeyDown={(event) => {
if (event.key === 'Escape') {
stopEdition(event);
cancelEdition(event);
setDescriptionText(value);
} else if (event.ctrlKey && event.key === 'Enter') {
stopEdition(event);
Expand All @@ -86,7 +92,7 @@ const DescriptionEditor = (props) => {
sx={{ pl: 1 }}
/>
);
}, [isEditing, readOnly, descriptionText, value, startEdition, stopEdition, t]);
}, [isEditing, readOnly, descriptionText, value, startEdition, stopEdition, cancelEdition, t]);

return (
<>
Expand Down

0 comments on commit b923038

Please sign in to comment.