Reputation: 186
I would like to add Add an Arrow to the Popover as we have for the ToolTip
Is there any possibility to Add an Arrow ??
Upvotes: 4
Views: 6547
Reputation: 167
Try the following:
import { Popover, type PopoverProps } from '@mui/material';
/**
* The `Popover` that:
* - is positioned at the bottom-right of the `anchorEl`, and
* - has an arrow pointing to the `anchorEl`.
*/
export const PopoverWithArrow = (popoverProps: Omit<PopoverProps, 'anchorOrigin' | 'transformOrigin'>) => (
<Popover
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
transformOrigin={{ horizontal: 'right', vertical: -5 }}
slotProps={{
paper: {
sx: {
overflow: 'visible',
'&:before': {
content: '""',
display: 'block',
position: 'absolute',
top: 0,
right: 8,
width: 10,
height: 10,
backgroundColor: 'inherit',
transform: 'translateY(-50%) rotate(45deg)',
boxShadow: '-3px -3px 5px -2px rgba(0,0,0,0.1)',
},
},
},
}}
{...popoverProps}
/>
);
To use, simply give it an anchor:
<PopoverWithArrow anchorEl={anchorEl}>
<h1>Your awesome Popover body content</h1>
</PopoverWithArrow>
Upvotes: 4
Reputation: 140
MUI docs has an example with arrow. And the code of this example can be found in their repo, which makes everything clear about the usage of modifiers and implementation of arrowRef
Upvotes: 0
Reputation: 496
According to the documentation, this snippet will do what you require
modifiers={[
{
name: 'arrow',
enabled: true,
options: {
element: arrowRef,
},
},
]}
See scroll playground https://mui.com/components/popper/
Upvotes: 6