这个 JSFiddle说明了这个问题。
我正在尝试使用react-bootstrap库在没有 React 的现有页面上显示 Popover。小提琴有一个香草 Bootstrap 弹出框的示例和一个使用 react-bootstrap 创建的示例。
存在三个错误:
弹出窗口未正确定位在元素上,它位于主体的顶部
在
<textarea>
元素 React 输出中<noscript data-reactid=".0"></noscript>
- 在控制台中它抛出错误
Uncaught Error: Invariant Violation: findComponentRoot(..., .0): Unable to find element. This probably means the DOM was unexpectedly mutated (e.g., by the browser), usually due to forgetting a <tbody> when using tables, nesting tags like <form>, <p>, or <a>, or using non-SVG elements in an <svg> parent. Try inspecting the child nodes of the element with React ID ``.
我确定我做错了什么,我只是不知道它是什么。
var Portal = ReactBootstrap.Portal;
var Popover = ReactBootstrap.Popover;
// Create the popup dynamically and show it with bootstrap
var $username = $('#username');
var showBootstrapPopover = function() {
$username.popover({
placement: 'top',
title: 'Vanilla Bootstrap Popover',
content: 'I am a vanilla Bootstrap Popover'
}).popover('show');
}
var MyPopover = React.createClass({
render: function() {
return (
<Portal container={document.body}
placement="bottom"
target={() => document.querySelector(this.props.target)}
show={true}>
<Popover title="React Popover">
<div>I should be on the bottom of the textarea</div>
</Popover>
</Portal>
);
}
});
var reactUsername = React.render(<MyPopover target="#username" show={true} />, document.querySelector('#username'));
showBootstrapPopover();
reactUsername.setState({ show: true });
<div>
<textarea id="username" rows="1" cols="60" type="text" class="form-control" placeholder="Username"></textarea>
</div>