首页 > 解决方案 > React 错误:无效的 DOM 属性 `tabindex` 。你的意思是 `tabIndex` 用 Bbootstrap 创建一个模式

问题描述

对不起我的英语:

我在 React 中创建了一个模态组件,编译良好,但控制台显示此错误:

警告:无效的 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">&times;</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>
)

};

标签: reactjsbootstrap-4bootstrap-modaljsx

解决方案


在 react 中,tabIndex 对应 html 中的 tabindex。将其更改为 tabIndex 并且模态应该按预期工作。


推荐阅读