reactjs - 如何从材料 ui 文本字段 i 中删除选择文件工具提示
问题描述
我只想在选择图像时在文本字段中显示图像名称,不想在 textfiled 中选择文件按钮
<TextField variant='outlined' fullWidth type="file"
InputProps={{ startAdornment: (
<InputAdornment position="start">
<PhotoCamera />
</InputAdornment>
)
}}
/>
解决方案
您可以在选择文件时将TextField的类型从文件更改为文本,并在输入字段中显示文件名。例子
const [file, setFile] = React.useState(null);
<TextField
variant="outlined"
fullWidth
value={file?.name||''}
type={!file ? "file" : "text"}
onChange={(e) => {
if (!file) setFile(e.target.files[0]);
}}
InputProps={{
startAdornment: (
<InputAdornment position="start">
<PhotoCamera />
</InputAdornment>
)
}}
/>
推荐阅读
- elixir - Elixir 混合测试集颜色默认为启用
- amazon-web-services - 301 redirect loop when setting up static website with S3, Cloudfront, SSL
- javascript - Agora VideoChat SDK 3.1.1 使用 JavaScript 出错
- wordpress - WooCommerce 如何显示特定的“附加信息”字段
- python - 使用正则表达式解析python字符串
- laravel - 如何获得已批准所有提交评估的主管
- docker-compose - 如何为 docker compose 服务指定多个“env_files”?
- python - 如何从请求数据中一一获取准确的项目?
- python-3.x - 如何在 Flask 和 jinja 中格式化负货币数字
- tensorflow - 如何更新 haarcascade_frontalface_default.xml 文件以进行更多人脸检测