I made a custom input field of type="file" as I didn't like the default one. To achieve this I did:
<input
#uploadFile
type="file"
id="uploadFile"
class="hidden-input"
accept="image/jpeg, .jpeg, image/png, .png, image/pjpeg, .jpg, .docx, .pdf"
(change)="selectFile($event.target.files[0])"
/>
<label [matTooltip]="Upload a file" for="uploadFile">
<mat-icon>folder_open</mat-icon>
</label>
so basically it hides the original input, and with the tag I can open the browse file window by clicking on the mat-icon.
This works well, but instead of label I wanted to use the tag <button mat-icon-button>
to have a nice ripple effect on the icon, but the "for"
used in the label doesn't work for <button>
.
If I wrap my mat-icon
inside the label tag with the above button tag, what would happen is, the button
looks how I want it, but when I click nothing happens, I suppose it's because the button
is above the label
, so the label
doesn't get the click, I tried using z-index
but wouldn't work.
Any ideas on how to solve this?
Add this link to your
index.html
To your
app.module
addMatIconModule
in Html:
In ts make
onchange
function:Just make a button whose click fires a click event on the hidden file input