有没有办法限制输入类型 = 文件的 Material UI TextFields 仅接受 pdf?

问题描述 投票:0回答:3

我试图让我的输入类型=文件来限制用户只能上传pdf。

我查了一下,发现使用accept属性会有帮助。但它无法使用 Material UI 文本字段。

我可以尝试什么解决方案吗?

javascript reactjs material-ui input-type-file
3个回答
17
投票

你试过这个吗:

<TextField type={"file"} inputProps={{accept:"application/pdf"}}/>

1
投票


0
投票

在 MUIv6 inputProps 中已弃用,因此您必须使用

slotProps
,正如他们在文档中所说,所以这就是解决方案:

<TextField
   type="file"
   slotProps={{
     input: {
       inputProps: {
         accept: // kind of files you want
       },
     },
   }}
/>
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.