React : Enter 键点击意外按钮

发布于 2025-01-12 18:35:02 字数 1469 浏览 3 评论 0原文

首先,我是 React 和 React Native 的初学者,并且正在接手一个项目。因此,很抱歉,如果您不知道所有详细信息,如果您了解该问题,请询问我您需要什么。而且我的英语不太流利,所以我对此表示歉意。 该代码是一个表单,包含一个输入和 2 个按钮。第一个用于添加文件,第二个用于提交文本。 当我在我的笔记本电脑、Android 手机甚至 iOS 模拟器上测试它时,如果我按 Enter 键,一切正常。 但是,当我的 CTO 在他的 iphone 12 上尝试时,回车键会在 Web 应用程序或 React Native 移动应用程序的 Web 视图中单击 addFile 按钮。 有人知道它来自哪里吗?

const handleSubmit = (e) => {
        if (messageValue === "") {
            e.preventDefault();
        } else {
            e.preventDefault();
            // On post le message
            postMessage();
            // On reset l'input
            setMessageValue("");
        }
    };
    const handleChange = (e) => {
        setMessageValue(e.target.value, cas.id);
    };

    return (
        <ContainerReponse>
            <ChatFormInput
                onSubmit={handleSubmit}
                type="text"
                label="Envoyer votre message"
                value={messageValue.message}
                onChange={handleChange}
                valueToActive={messageValue}
                required={true}
            >
                <SendButton disabled={!messageValue ? true : false}/>
            </ChatFormInput>
        </ContainerReponse>

这是 组件的按钮元素:

<button disabled={disabled} type="submit" value="Envoyer" className="sendButton orange send-message">
    Envoyer
</button>

谢谢您的好意

First of all, I am a beginner in React and React Native, and I am taking on a project. So, sorry if you don't have al the details, ask me what you need if you have an idea of the issue. And I am not fluent English, so I apologize for that.
The code is a form, containing an input, and 2 butons. The first one to add a file, the second one for submitting the text.
When I test it on my laptop, android mobile or even on ios simulator, if I press enter key, everything works fine.
But when my CTO tries it on his iphone 12, the enter key clicks on the addFile button, in the web app or in the web viw of the react native mobile app.
Does somebody know where does it comes from ?

const handleSubmit = (e) => {
        if (messageValue === "") {
            e.preventDefault();
        } else {
            e.preventDefault();
            // On post le message
            postMessage();
            // On reset l'input
            setMessageValue("");
        }
    };
    const handleChange = (e) => {
        setMessageValue(e.target.value, cas.id);
    };

    return (
        <ContainerReponse>
            <ChatFormInput
                onSubmit={handleSubmit}
                type="text"
                label="Envoyer votre message"
                value={messageValue.message}
                onChange={handleChange}
                valueToActive={messageValue}
                required={true}
            >
                <SendButton disabled={!messageValue ? true : false}/>
            </ChatFormInput>
        </ContainerReponse>

And this is the button element of the <SendButton/> component :

<button disabled={disabled} type="submit" value="Envoyer" className="sendButton orange send-message">
    Envoyer
</button>

Thank you for you kindness

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文