I am attempting to add a Tooltip to wrap the KeyboardDatePicker and simply wrapping it in the Tooltip provides the following error:
Warning: Failed prop type: Invalid prop
children
supplied toForwardRef(Tooltip)
. Expected an element that can hold a ref. Did you accidentally use a plain function component for an element instead? For more information see https://material-ui.com/r/caveat-with-refs-guide in ForwardRef(Tooltip) (created by WithStyles(ForwardRef(Tooltip)))in WithStyles(ForwardRef(Tooltip)) (at src/index.js:17)
in MuiPickersUtilsProvider (at src/index.js:16)
in App (at src/index.js:33)
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
Check the render method of
ForwardRef(Tooltip)
. in PickerWithState (at src/index.js:19) in ForwardRef(Tooltip) (created by WithStyles(ForwardRef(Tooltip))) in WithStyles(ForwardRef(Tooltip)) (at src/index.js:17) in MuiPickersUtilsProvider (at src/index.js:16) in App (at src/index.js:33)
If I wrap the tooltip in a it gets around the error but it seems like a hack and the tooltip is not aligned properly below the field. In my reading of ForwardRef I can't figure out how to solve this here. Can anyone help solve this correctly?
https://codesandbox.io/s/mui-pickers-tooltip-1hsn2
import React, { useState } from "react";
import ReactDOM from "react-dom";
import DayjsUtils from "@date-io/dayjs";
import {
MuiPickersUtilsProvider,
KeyboardDatePicker
} from "@material-ui/pickers";
import { Tooltip } from "@material-ui/core";
function App() {
const [selectedDate, handleDateChange] = useState();
return (
<MuiPickersUtilsProvider utils={DayjsUtils}>
<Tooltip placement={"bottom"} title={"This tooltip overlaps"}>
{/*<span>*/}
<KeyboardDatePicker
label={"hello"}
variant="inline"
autoOk
value={selectedDate}
onChange={handleDateChange}
/>
{/*</span>*/}
</Tooltip>
</MuiPickersUtilsProvider>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);