最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there a way to limit Material UI TextFields of input type = file to accept only pdf? - Stack Overflow

programmeradmin1浏览0评论

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
  • you can use the accept attribute <input type="file" accept=".pdf"> – AngelSalazar Commented May 4, 2021 at 21:01
Add a comment  | 

3 Answers 3

Reset to default 17

Have 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
       },
     },
   }}
/>
发布评论

评论列表(0)

  1. 暂无评论