Skip to content
Open
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
11 changes: 8 additions & 3 deletions src/framework/theme/components/chat/_chat.component.theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,15 @@
flex-direction: row;
display: flex;
}

input {
textarea {
resize: none;
max-height: 15em;
height: auto;
overflow-y: auto;
}
input,
textarea {
flex: 1;

&.with-button {
border-bottom-right-radius: 0;
border-top-right-radius: 0;
Expand Down
33 changes: 33 additions & 0 deletions src/framework/theme/components/chat/chat-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,25 @@ import { NbComponentOrCustomStatus } from '../component-status';
</ng-container>
</div>
<div class="message-row">
<textarea
*ngIf="multiline"
nbInput
fullWidth
[status]="getInputStatus()"
(focus)="inputFocus = true"
(blur)="inputFocus = false"
(mouseenter)="inputHover = true"
(mouseleave)="inputHover = false"
[(ngModel)]="message"
(input)="adjustTextareaHeight($event)"
rows="1"
(ngModelChange)="onModelChange($event)"
[class.with-button]="showButton"
placeholder="{{ fileOver ? dropFilePlaceholder : messagePlaceholder }}"
(keyup.enter)="sendMessage()"
></textarea>
<input
*ngIf="!multiline"
nbInput
fullWidth
[status]="getInputStatus()"
Expand Down Expand Up @@ -141,6 +159,12 @@ export class NbChatFormComponent {
*/
@Input() dropFilePlaceholder: string = 'Drop file to send';

/**
* Allow multiline input
* @type {boolean}
*/
@Input() multiline: boolean = false;

/**
*
* @type {EventEmitter<{ message: string, files: File[] }>}
Expand Down Expand Up @@ -252,4 +276,13 @@ export class NbChatFormComponent {
onModelChange(value: string): void {
this.onInputChange.emit(value);
}

adjustTextareaHeight(event: Event): void {
const textarea = event.target as HTMLTextAreaElement;
if (textarea) {
textarea.style.height = 'auto';
const computedHeight = textarea.scrollHeight;
textarea.style.height = computedHeight + 'px';
}
}
}