I am trying to make my input type=file to limit the user to only upload pdf.
I looked it up and saw that using accept attribute can help. But it is not working using material UI text fields.
Any solution I can try?
I am trying to make my input type=file to limit the user to only upload pdf.
I looked it up and saw that using accept attribute can help. But it is not working using material UI text fields.
Any solution I can try?
Share Improve this question asked May 4, 2021 at 20:57 husseinndhusseinnd 1352 silver badges7 bronze badges 1 |3 Answers
Reset to default 17Have you tried this:
<TextField type={"file"} inputProps={{accept:"application/pdf"}}/>
<TextField type={"file"} inputProps={{accept:"application/pdf"}}/>
in MUIv6 inputProps is deprecated, so you have to use slotProps
as they said on the docs, so this is the solution:
<TextField
type="file"
slotProps={{
input: {
inputProps: {
accept: // kind of files you want
},
},
}}
/>
<input type="file" accept=".pdf">
– AngelSalazar Commented May 4, 2021 at 21:01