React Bootstrap故障w/ButtonGroup或将模态放在哪里
React-Bootstrap trouble w/ ButtonGroup OR where to put modals?
在react引导程序中,我试图创建一个可重复使用的按钮类,该类在单击时显示模式。最终,Modal
将包含一个"编辑"表单,用于修改表/列表中的多个条目之一。
在这里,我将问题简化为一个简单的"确认"对话框,试图获得一个最低限度完整的示例。
我遇到的问题是在ButtonGroup
中嵌入与Button
内联的Modal
会破坏按钮组的格式。具体而言,自定义ConfirmActionButton
将显示为独立按钮,而不是组的一部分。
我知道我可以通过将Modal
完全移动到ButtonGroup
之外来解决布局问题(也许这是正确的做法?),但这似乎没有很好地封装/模块化。
有没有一种方法可以让这个渲染像一个普通的按钮组?或者,重新安排莫代尔人的居住地是唯一真正的前进之路吗?
以下是我在jsfiddle中的示例:
/* A bunch of var 'X = ReactBootstrap.X' lines ommitted here */
var ConfirmActionButton = React.createClass({
getInitialState : function(){
return {show : false};
},
ok : function(){
this.setState({showModal:false});
this.props.onClick();
},
cancel : function(){
this.setState({showModal:false});
},
show : function(){
this.setState({showModal:true});
},
render : function() {
return (
<span>
<Button onClick={this.show} >
{this.props.children}
</Button>
<Modal show={this.state.showModal} >
<ModalHeader>Confirm</ModalHeader>
<ModalBody>{this.props.confirmMessage}</ModalBody>
<ModalFooter>
<Button onClick={this.cancel}>Ok</Button>
<Button onClick={this.ok}>Ok</Button>
</ModalFooter>
</Modal>
</span>
);
}
});
var MyToolbar = React.createClass({
render: function(){
return (
<ButtonToolbar>
<ButtonGroup>
<Button>Click Here</Button>
<Button>No, Here</Button>
<ConfirmActionButton confirmMessage="Are you sure?"
onClick={this.someAction}
>
Do Something
</ConfirmActionButton>
</ButtonGroup>
</ButtonToolbar>
);
},
someAction : function()
{
alert("you did it");
},
});
ReactDOM.render(
<div>
<MyToolbar />
</div>,
document.getElementById('example')
);
您只需将<Modal />
放在<ConfirmActionButton />
的<Button />
中,并移除正在破坏btn-grp
布局的<span>
。
<Button onClick={this.show} >
{this.props.children}
<Modal show={this.state.showModal} >
<ModalHeader>Confirm</ModalHeader>
<ModalBody>{this.props.confirmMessage}</ModalBody>
<ModalFooter>
<Button onClick={this.cancel}>Cancel</Button>
<Button onClick={this.ok}>Ok</Button>
</ModalFooter>
</Modal>
</Button>
相关文章:
- 打开一个模态(在Codeigniter中),该模态从依赖于phpvar的URL加载(在iframe中)内容
- 引导模态在单击其正文时会触发其他模态
- JavaScript 使模态在 Rails 中提交表单
- 模态在IE9中不起作用 - 在打开开发人员工具时,它可以正常工作
- 离子模态:在单击/取消时清除所有字段
- 模态在Twitter boootstrap中不可见
- React Bootstrap故障w/ButtonGroup或将模态放在哪里
- 为什么获胜'我的模态在窗户的死点开着
- 控制器上的模态在AngularJS上不起作用
- Onsen UI模态在angularjs中是不隐藏的
- Laravel模态在blade的脚本中不起作用
- 引导模态在关闭后不断向身体添加填充权
- 如何使模态在html页面运行时默认可见
- 谷歌地图出现灰色内模态在引导
- 我的模态在Bootstrap中不起作用,我看不出有什么问题
- 模态在加载时出现
- 使模态在提交rails后关闭
- Boostrap 模态在使用 jquery 连接时不加载
- 我如何保持用户输入后关闭模态在同一页面没有重新加载
- 启动模态在条件下打开