I'm trying using react-poper to create a title on hover to my component. I follow basic document to create test sample but the modifiers seem like not working.
No matter value of offset i set, the popup title alway show up at top: 0; left: 0
when the page got loaded.
Weird thing is when i change offset in code, then the custom modifiers will work like a charm.
Is anyone got this issue before? Is my code break some where, please point out for me. Thankyou!
js file:
import React, { useRef } from "react";
import { usePopper } from "react-popper";
import styled from "styled-components";
const Dropdown = () => {
const buttonRef = useRef(null);
const popperRef = useRef(null);
// the ref for the arrow must be a callback ref
const { styles, attributes } = usePopper(
buttonRef.current,
popperRef.current,
{
modifiers: [
{
name: "offset",
options: {
offset: [0, 100]
}
}
]
}
);
console.log(styles);
return (
<>
<Warper ref={buttonRef}>
Hover Me
<PopperContainer
ref={popperRef}
style={styles.popper}
{...attributes.popper}
>
<p>I'm a popper</p>
</PopperContainer>
</Warper>
</>
);
};
// a basic page styling
const PopperContainer = styled.div`
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
border-radius: 5px;
background-color: white;
padding: 20px;
text-align: center;
visibility: hidden;
`;
const Warper = styled.div`
position: relative;
background: lightblue;
border: none;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
width: 150px;
height: 50px;
outline: none;
&:hover ${PopperContainer} {
visibility: visible;
}
`;
export default Dropdown;