Files
react-test/docs/data/material/components/tooltips/AnchorElTooltips.js
how2ice 005cf56baf
Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
init project
2025-12-12 14:26:25 +09:00

52 lines
1.1 KiB
JavaScript

import * as React from 'react';
import Box from '@mui/material/Box';
import Tooltip from '@mui/material/Tooltip';
export default function AnchorElTooltips() {
const positionRef = React.useRef({
x: 0,
y: 0,
});
const popperRef = React.useRef(null);
const areaRef = React.useRef(null);
const handleMouseMove = (event) => {
positionRef.current = { x: event.clientX, y: event.clientY };
if (popperRef.current != null) {
popperRef.current.update();
}
};
return (
<Tooltip
title="Add"
placement="top"
arrow
slotProps={{
popper: {
popperRef,
anchorEl: {
getBoundingClientRect: () => {
return new DOMRect(
positionRef.current.x,
areaRef.current.getBoundingClientRect().y,
0,
0,
);
},
},
},
}}
>
<Box
ref={areaRef}
onMouseMove={handleMouseMove}
sx={{ bgcolor: 'primary.main', color: 'primary.contrastText', p: 2 }}
>
Hover
</Box>
</Tooltip>
);
}