简体   繁体   English

当在 Zurb Foundation“显示”对话框中时,React 表单 onSubmit 和 onClick 不会触发

[英]React form onSubmit and onClick do not fire when inside Zurb Foundation "Reveal" dialog

I have the following code, which worked perfectly prior to upgrading from React 16.12.0 to React 17.0.0, but now my events no longer fire (ie the console.log statement is never printed).我有以下代码,它在从 React 16.12.0 升级到 React 17.0.0 之前运行良好,但现在我的事件不再触发(即, console.log语句从不打印)。

class MyClass extends PureComponent {
    handleSubmit = () => {
        console.log('Submitted!');
    };

    render() {
        return (
            <div className='reveal' id='dialog'>
                <form onSubmit={this.handleSubmit}>
                    <button type='submit'>Submit</button>
                </form>
            </div>
        );
    }
}

I've tried changing my code to the following instead, but this event does not fire either.我已尝试将代码更改为以下代码,但此事件也不会触发。

class MyClass extends PureComponent {
    handleSubmit = () => {
        console.log('Submitted!');
    };

    render() {
        return (
            <div className='reveal' id='dialog'>
                <form>
                    <button onClick={this.handleSubmit} type='submit'>Submit</button>
                </form>
            </div>
        );
    }
}

I know this has something to do with the fact that the form is inside a Zurb Foundation "Reveal" dialog, but I have no idea why this problem only occurs when upgrading to React 17.我知道这与表单位于 Zurb Foundation“Reveal”对话框内的事实有关,但我不知道为什么只有在升级到 React 17 时才会出现这个问题。

I'm unable to reproduce this – works just fine in this minimal example derived from your code.我无法重现这一点 - 在这个源自您的代码的最小示例中工作得很好。

 class MyClass extends React.PureComponent { handleSubmit = () => { alert('Submitted!'); }; render() { return ( <form onSubmit={this.handleSubmit}> <button type='submit'>Submit</button> </form> ); } } ReactDOM.render(<MyClass />, document.getElementById("root"));
 <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.0/umd/react.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.0/umd/react-dom.production.min.js"></script> <div id="root" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM