【问题标题】:React Error: Invalid DOM property `tabindex` . Did you mean `tabIndex` Creating a modal with BbootstrapReact 错误:无效的 DOM 属性 `tabindex` 。你的意思是 `tabIndex` 用 Bootstrap 创建一个模式
【发布时间】: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">&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>
)

};

【问题讨论】:

  • tabIndex 应该在 DOM 中转换为 tabindex。你确定让它tabIndex 没用吗?可能是代码的其他部分有问题。

标签: reactjs bootstrap-4 bootstrap-modal jsx


【解决方案1】:

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

【讨论】:

  • 是的,我必须放 tabIndex 但是,问题最终出在数据目标中,必须在 de ID 之前有 #。谢了。
猜你喜欢
  • 2020-04-16
  • 2020-09-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-12
  • 2021-09-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多