How to trigger click call from code in Safari

Viewed 195

I need to trigger a file input control without showing the default file "Select" button. In Chrome, I am able to call this.fileInput.nativeElement.click() and trigger the file finder dialog open. However, in Safari 14.1.1, the file dialog does not get popped up. The html snippet:

<input
  #fileInput
  type="file"
>

In Angular component .ts file:

@ViewChild("fileInput") fileInput: ElementRef;
...
activateFileInput() {
  this.fileInput.nativeElement.click()
}

Calling activateFileInput() method opens the file dialog in Chrome or Firefox, but not in Safari (I am testing with Safari 14.1.1).

0 Answers
Related