Skip to content

Commit

Permalink
Merge pull request #113 from Lemoncode/feature/#112-focus-is-set-sele…
Browse files Browse the repository at this point in the history
…ct-all-text-as-well

add select all text as well
  • Loading branch information
brauliodiez authored Aug 2, 2024
2 parents 3d86d86 + 1662f6f commit 4809035
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/common/components/inline-edit/inline-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@ export const EditableComponent: React.FC<Props> = props => {
!inputRef.current.contains(event.target as Node)
) {
setIsEditing(false);
onTextSubmit(editText);
onTextSubmit(inputRef.current?.value || '');
}
};

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

if (isEditing) {
inputRef.current?.focus();
inputRef.current?.select();
document.addEventListener('mousedown', handleClickOutside);
document.addEventListener('keydown', handleKeyDown);
} else {
Expand All @@ -58,7 +59,7 @@ export const EditableComponent: React.FC<Props> = props => {
document.removeEventListener('mousedown', handleClickOutside);
document.addEventListener('keydown', handleKeyDown);
};
}, [isEditing, editText]);
}, [isEditing]);

const handleDoubleClick = () => {
if (isEditable) {
Expand Down

0 comments on commit 4809035

Please sign in to comment.