【发布时间】:2020-09-29 05:59:22
【问题描述】:
对不起我的英语:
我在React中创建了一个modal的组件,编译好,但是控制台显示这个错误:
警告:无效的 DOM 属性 tabindex。你是说tabIndex吗?在 div 中(在 ModalComponent.js:10) 在 div 中(在 ModalComponent.js:5) 在 ModalComponent 中(在 src/index.js:24) 在 div 中(在 src/index.js:23) 在 ModalCreate(在 src/ index.js:32) 在 StrictMode (在 src/index.js:31)
我知道在反应中属性必须是 camalCase 但引导程序需要这个属性才能工作。有我的代码:
const ModalComponent = (props) => {
return (
<div> {/* Tiene qe haber un solo elemento Padre */}
<button type="button" className="btn btn-primary" data-toggle="modal" data-target={props.obj.id}>
{props.obj.btnCallModal}
</button>
<div className="modal fade" id={props.obj.id} tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div className="modal-dialog" role="document">
<div className="modal-content">
<div className="modal-header">
<h5 className="modal-title" id="exampleModalLabel">{props.obj.titulo}</h5>
<button type="button" className="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div className="modal-body">
{props.obj.body}
</div>
<div className="modal-footer">
<button type="button" className="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" className="btn btn-primary">{props.obj.btnInModal}</button>
</div>
</div>
</div>
</div>
</div>
)
};
【问题讨论】:
-
tabIndex应该在 DOM 中转换为tabindex。你确定让它tabIndex没用吗?可能是代码的其他部分有问题。
标签: reactjs bootstrap-4 bootstrap-modal jsx