Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

fix: call focus on comments textarea input when clicking on it #577

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/web-components/comments/components/comment-input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,13 @@ describe('CommentsCommentInput', () => {
expect(mockCancelComment).toHaveBeenCalled();
});
});

describe('focusInput', () => {
test('should focus keyboard cursor on input when clicking on it', () => {
element['getCommentInput']().focus = jest.fn();
element['focusInput']();

expect(element['getCommentInput']().focus).toHaveBeenCalled();
});
});
});
13 changes: 9 additions & 4 deletions src/web-components/comments/components/comment-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ export class CommentsCommentInput extends WebComponentsBaseElement {
disconnectedCallback(): void {
super.disconnectedCallback();
if (!['create-annotation', 'create-comment'].includes(this.eventType)) return;
const textarea = this.getCommentInput();

this.removeEventListener('keyup', this.sendEnter);
const textarea = this.getCommentInput();
textarea.removeEventListener('keydown', this.sendEnter);
textarea.removeEventListener('click', this.focusInput);
textarea.addEventListener('input', this.handleInput);
}

protected firstUpdated(
Expand All @@ -115,9 +117,8 @@ export class CommentsCommentInput extends WebComponentsBaseElement {

if (commentTextarea) {
commentTextarea.addEventListener('input', this.handleInput);

const textarea = this.getCommentInput();
textarea.addEventListener('keydown', this.sendEnter);
commentTextarea.addEventListener('click', this.focusInput);
commentTextarea.addEventListener('keydown', this.sendEnter);
}

if (this.text.length > 0) {
Expand Down Expand Up @@ -171,6 +172,10 @@ export class CommentsCommentInput extends WebComponentsBaseElement {
return { searchText, position };
};

private focusInput = () => {
this.getCommentInput().focus();
};

private handleInput = (e: InputEvent) => {
if (this.commentInput?.value.length === 0) this.btnActive = false;
else this.btnActive = true;
Expand Down
Loading