如何更改“文件”的文本。 <输入> Antd

发布于 2025-02-02 12:54:33 字数 649 浏览 4 评论 0原文

我相信标题是不言自明的。我已经检查了文档和其他一些线程,但是我根本无法设法更改标签的两个文本:也不是“选择文件”,也不是“不选择文件”。下面是我到目前为止尝试过的。我该如何更改这些文本?

 {/* <label htmlFor="test" id="files">Test with classic label</label> */}
                  <Input
                  // addonAfter="test1"
                  // addonBefore="test2"
                    type="file"
                    onChange={handleFileSelected}
                    text="test"
                  />

I believe the title is self-explanatory. I have checked the docs and some other threads, but I simply cannot manage to change both texts of the label: nor "Choose file", neither "No file chosen". Below is what I have tried so far. How could I change those texts? enter image description here

 {/* <label htmlFor="test" id="files">Test with classic label</label> */}
                  <Input
                  // addonAfter="test1"
                  // addonBefore="test2"
                    type="file"
                    onChange={handleFileSelected}
                    text="test"
                  />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩世 2025-02-09 12:54:33

输入的文件元素的文本由浏览器控制,因此您无法直接更改该元素。您可以做的是创建一个可自定义的按钮,该按钮使用参考来控制输入的单击:

const ref = useRef<HTMLInputElement>(null);
<button onClick={() => ref.current?.click()}>Click Here</button>
<input 
 type='file' 
 ref={ref} 
 onChange={handleFileSelected}
 style={{ display: "none" }} />

The text of the input's file element is controlled by the browser so you can not directly change that. What you can do is instead creating a customizable button that uses a ref to control the click on the input:

const ref = useRef<HTMLInputElement>(null);
<button onClick={() => ref.current?.click()}>Click Here</button>
<input 
 type='file' 
 ref={ref} 
 onChange={handleFileSelected}
 style={{ display: "none" }} />
嘴硬脾气大 2025-02-09 12:54:33

蚂蚁设计还具有 upload组件用于文件上传的文件上传,可以轻松样式上载

Ant Design also has Upload component for file uploading which could be styled easily

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文