【发布时间】:2017-03-29 16:41:48
【问题描述】:
我是 React 的新手,我正在尝试使用 materialize.css http://materializecss.com 创建一个模式
我的登录页面如下所示
import React from 'react';
var Modal=require('Modal');
class login extends React.Component{
constructor(props){
super(props);
this.state={
view: {showModal: false}
}
this.handleHideModal=this.handleHideModal.bind(this);
this.handleShowModal=this.handleShowModal.bind(this);
}
handleHideModal(){
this.setState({view: {showModal: false}})
}
handleShowModal(){
$('#modal1').modal('open');
}
componentDidMount(){
$('#modal1').modal('open');
}
render(){
return(
<div>
<div className="login">
<div className="">
<div className="input-field col s8">
<i className="material-icons prefix">account_circle</i>
<input id="username" type="text" className="validate"/>
<label htmlFor="username">User Name</label>
</div>
<div className="input-field col s8">
<i className="material-icons prefix">vpn_key</i>
<input id="password" type="password" className="validate"/>
<label htmlFor="password">Password</label>
</div>
<div className="center input-field col s6">
<input type="checkbox" className="filled-in" id="filled-in-box" defaultChecked="checked" />
<label htmlFor="filled-in-box">Remember me</label>
</div>
<div className="center input-field col s12">
<a className="login-button waves-effect waves-light btn center">Login</a>
</div>
<div className="row input-field col s12">
<div className="col s6 left-align">
<a className="modal-trigger " onClick={this.handleShowModal} >Register Now</a>
</div>
<div className="col s6 right-align">
<a>Forgot Password?</a>
</div>
</div>
</div>
</div>
{this.state.view.showModal ? <Modal handleHideModal={this.handleHideModal}/>:null}
</div>
);
}
};
module.exports= login;
我的模态组件看起来像这样。
import React from 'react';
import ReactDOM from 'react-dom';
class Modal extends React.Component{
componentDidMount(){
//var modal = new Foundation.Reveal($('#modal1'));
//modal.open();
$('#modal1').open();
$(ReactDOM.findDOMNode('#modal1')).modal('show');
//$(ReactDOM.findDOMNode(this)).on('hidden.bs.modal', this.props.handleHideModal);
}
render(){
return(
<div id="modal1" className="modal">
<div className="modal-content">
<h4>Modal Header</h4>
<p>A bunch of text</p>
</div>
<div className="modal-footer">
<a href="#!" className="modal-action modal-close waves-effect waves-green btn-flat">Agree</a>
</div>
</div>
);
}
propTypes:{
handleHideModal: React.PropTypes.func.isRequired
}
};
module.exports = Modal;
我尝试了很多在互联网上找到的建议,但都没有成功。我不明白问题是什么。
【问题讨论】:
-
你有没有让模态显示?我遇到了类似的问题,只是在调用 open 时我没有收到错误。什么都没有发生。我的设置和你一样。下面的答案也不起作用。另外,material-react Modal 现在已经坏掉了。
标签: reactjs modal-dialog materialize