Skip to content

Commit

Permalink
fix(chat): file drop in firefox (#2776)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreipadolin committed Nov 9, 2021
1 parent 3795905 commit 07db7f5
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions src/framework/theme/components/chat/chat-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,29 @@ import { NbComponentOrCustomStatus } from '../component-status';
</ng-container>
</div>
<div class="message-row">
<input nbInput
fullWidth
[status]="getInputStatus()"
(focus)="inputFocus = true"
(blur)="inputFocus = false"
(mouseenter)="inputHover = true"
(mouseleave)="inputHover = false"
[(ngModel)]="message"
(ngModelChange)="onModelChange($event)"
[class.with-button]="showButton"
type="text"
placeholder="{{ fileOver ? dropFilePlaceholder : messagePlaceholder }}"
(keyup.enter)="sendMessage()">
<button nbButton
[status]="getButtonStatus()"
*ngIf="showButton"
[class.with-icon]="!buttonTitle"
(click)="sendMessage()"
class="send-button">
<input
nbInput
fullWidth
[status]="getInputStatus()"
(focus)="inputFocus = true"
(blur)="inputFocus = false"
(mouseenter)="inputHover = true"
(mouseleave)="inputHover = false"
[(ngModel)]="message"
(ngModelChange)="onModelChange($event)"
[class.with-button]="showButton"
type="text"
placeholder="{{ fileOver ? dropFilePlaceholder : messagePlaceholder }}"
(keyup.enter)="sendMessage()"
/>
<button
nbButton
[status]="getButtonStatus()"
*ngIf="showButton"
[class.with-icon]="!buttonTitle"
(click)="sendMessage()"
class="send-button"
>
<nb-icon *ngIf="!buttonTitle; else title" [icon]="buttonIcon" pack="nebular-essentials"></nb-icon>
<ng-template #title>{{ buttonTitle }}</ng-template>
</button>
Expand All @@ -89,7 +93,6 @@ import { NbComponentOrCustomStatus } from '../component-status';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class NbChatFormComponent {

status: NbComponentOrCustomStatus = 'basic';
inputFocus: boolean = false;
inputHover: boolean = false;
Expand Down Expand Up @@ -142,18 +145,18 @@ export class NbChatFormComponent {
*
* @type {EventEmitter<{ message: string, files: File[] }>}
*/
@Output() send = new EventEmitter<{ message: string, files: File[] }>();
@Output() send = new EventEmitter<{ message: string; files: File[] }>();

/**
* Emits when message input value has been changed
* @type {EventEmitter<string>}
*/
// eslint-disable-next-line @angular-eslint/no-output-on-prefix
@Output() onInputChange = new EventEmitter<string>();

@HostBinding('class.file-over') fileOver = false;

constructor(protected cd: ChangeDetectorRef, protected domSanitizer: DomSanitizer) {
}
constructor(protected cd: ChangeDetectorRef, protected domSanitizer: DomSanitizer) {}

@HostListener('drop', ['$event'])
onDrop(event: any) {
Expand All @@ -163,7 +166,6 @@ export class NbChatFormComponent {

this.fileOver = false;
if (event.dataTransfer && event.dataTransfer.files) {

for (const file of event.dataTransfer.files) {
const res = file;

Expand All @@ -190,15 +192,19 @@ export class NbChatFormComponent {
}
}

@HostListener('dragover')
onDragOver() {
@HostListener('dragover', ['$event'])
onDragOver(event: DragEvent) {
event.preventDefault();
event.stopPropagation();
if (this.dropFiles) {
this.fileOver = true;
}
}

@HostListener('dragleave')
onDragLeave() {
@HostListener('dragleave', ['$event'])
onDragLeave(event: DragEvent) {
event.preventDefault();
event.stopPropagation();
if (this.dropFiles) {
this.fileOver = false;
}
Expand Down Expand Up @@ -246,5 +252,4 @@ export class NbChatFormComponent {
onModelChange(value: string): void {
this.onInputChange.emit(value);
}

}

0 comments on commit 07db7f5

Please sign in to comment.