Skip to content

Commit

Permalink
Merge pull request #3502 from ita-social-projects/bugfix/#7938-remove…
Browse files Browse the repository at this point in the history
…-placeholder-on-image-select

[Bugfix] #7938 Remove placeholder on image select
  • Loading branch information
hnativlyubomyr authored Dec 23, 2024
2 parents 99b9cf4 + 4d1dd97 commit a2339aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

.comment-textarea-uploader {
position: relative;
width: 100%;
width: calc(100% - 1px);

.cancel-btn {
font-size: 18px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,7 @@ export class CommentTextareaComponent implements OnInit, AfterViewInit, OnChange
}

onCommentTextareaFocus(): void {
const currentText = this.commentTextarea.nativeElement.textContent.trim();
if (currentText === 'Add a comment' || currentText === '') {
this.commentTextarea.nativeElement.textContent = '';
}

this.clearPlaceholderIfNeeded();
const range = document.createRange();
const nodeAmount = this.commentTextarea.nativeElement.childNodes.length;
range.setStartAfter(this.commentTextarea.nativeElement.childNodes[nodeAmount - 1]);
Expand Down Expand Up @@ -246,6 +242,8 @@ export class CommentTextareaComponent implements OnInit, AfterViewInit, OnChange
file: fileHandle.file
});
}

this.clearPlaceholderIfNeeded();
this.isImageUploaderOpen = false;
this.showImageControls = true;
this.emitComment();
Expand All @@ -267,6 +265,18 @@ export class CommentTextareaComponent implements OnInit, AfterViewInit, OnChange
});
}

private clearPlaceholderIfNeeded(): void {
const currentText = this.commentTextarea?.nativeElement?.textContent?.trim() || '';
if (this.isPlaceholderText(currentText)) {
this.commentTextarea.nativeElement.textContent = '';
this.content.setValue('');
}
}

private isPlaceholderText(text: string): boolean {
return text === 'Add a comment' || text === '';
}

private insertTextAtCursor(text: string): void {
const selection = window.getSelection();
const range = selection.getRangeAt(0);
Expand Down

0 comments on commit a2339aa

Please sign in to comment.