我需要将我的自定义组件包装在 Material UI Tooltip 中。我相信我正在正确使用 ForwardRefs,但是无论事件如何(悬停、单击等),工具提示都不会出现
const MyComp = ({ buttonRef }) => {
return <button ref={buttonRef}>this does not work</button>;
};
const MyCompForwardRef = React.forwardRef((props, ref) => {
return <MyComp {...props} buttonRef={ref} />;
});
const FancyButton = React.forwardRef((props, ref) => (
<button ref={ref}>this also does not work</button>
));
const Page = () => (
<div style={{ display: "flex", flexDirection: "column" }}>
<div style={{ margin: "10px" }}>
<Tooltip title="23456789">
//not working
<MyCompForwardRef />
</Tooltip>
</div>
<div style={{ margin: "10px" }}>
<Tooltip title="23456789">
//not working
<FancyButton />
</Tooltip>
</div>
<div style={{ margin: "10px" }}>
<Tooltip title="23456789">
<button>this works</button>
</Tooltip>
</div>
</div>);
这是沙盒链接https://codesandbox.io/s/material-ui-card-styling-example-forked-9tqod?file=/src/index.js:438-914