`popover'(作为react组件)用`
我正在尝试将丰富的React组件作为弹出内容创建。
如果我将示例与简单 const popover
()一切正常。
问题,
const MyPopover = React.forwardRef((props, ref) => {
return <Popover ref={ref} placement={"bottom"}>
<Popover.Header as="h3">
<Form.Control></Form.Control>
</Popover.Header>
<Popover.Body>
<strong>Holy guacamole!</strong> Check this info.
</Popover.Body>
</Popover>
})
const PopoverChooser = ({children, container}) => {
const _refTarget = useRef(null)
return <>
<OverlayTrigger
trigger="click"
placement="bottom"
overlay={<MyPopover ref={_refTarget}/>}
target={_refTarget.current}
>
{children}
</OverlayTrigger>
</>
}
export default PopoverChooser;
如您所见,我尝试使用 ref
's,但这无济于事。
问题
- 如何将弹出键链链接到目标按钮(如下拉按钮中的图像中,在代码中为
{children {children}
)。 - 还是我应该手动定位
mypopover
(通过检查按钮ID并分配位置等。等等?) - 完全不同的方法来挖掘..?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您转发裁判的方法是正确的。您实际忘记的是注入道具。根据文档:
httpps://react-bootstrap.netlify.app/components/components/poverlays/poverlays/poverlays/poverlays/poverview <<<<<<<<<<<<<<<< /a>
因此,您需要做的是传播这样的道具:
https:// codesandbox box .io/s/s/trusting-sid-0050g9
Your approach to forward the ref was right. What you actually forgot is to also inject props. According to the documentation:
https://react-bootstrap.netlify.app/components/overlays/#overview
So what you need to do is to spread the props like this:
https://codesandbox.io/s/trusting-sid-0050g9