Skip to content

Commit

Permalink
Fixed #10575 - Problem with keydown for FileUpload component
Browse files Browse the repository at this point in the history
  • Loading branch information
yigitfindikli committed Dec 8, 2021
1 parent 46be1a0 commit d54c385
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/app/components/fileupload/fileupload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import {Subscription} from 'rxjs';
<div class="p-fileupload p-fileupload-basic p-component" *ngIf="mode === 'basic'">
<p-messages [value]="msgs" [enableService]="false"></p-messages>
<span [ngClass]="{'p-button p-component p-fileupload-choose': true, 'p-button-icon-only': !chooseLabel, 'p-fileupload-choose-selected': hasFiles(),'p-focus': focus, 'p-disabled':disabled}"
[ngStyle]="style" [class]="styleClass" (mouseup)="onBasicUploaderClick()" (keydown)="onBasicUploaderClick()" tabindex="0" pRipple>
[ngStyle]="style" [class]="styleClass" (mouseup)="onBasicUploaderClick()" (keydown)="onBasicKeydown($event)" tabindex="0" pRipple>
<span class="p-button-icon p-button-icon-left pi" [ngClass]="hasFiles()&&!auto ? uploadIcon : chooseIcon"></span>
<span class="p-button-label">{{auto ? chooseLabel : hasFiles() ? files[0].name : chooseLabel}}</span>
<input #basicfileinput type="file" [accept]="accept" [multiple]="multiple" [disabled]="disabled"
Expand Down Expand Up @@ -550,6 +550,17 @@ export class FileUpload implements AfterViewInit,AfterContentInit,OnInit,OnDestr
this.basicFileInput.nativeElement.click();
}

onBasicKeydown(event: KeyboardEvent) {
switch(event.code) {
case 'Space':
case 'Enter':
this.onBasicUploaderClick();

event.preventDefault();
break;
}
}

getBlockableElement(): HTMLElement {
return this.el.nativeElement.children[0];
}
Expand Down

0 comments on commit d54c385

Please sign in to comment.