Skip to content

Commit

Permalink
fix(popup): Fix wrong placement of Popper refs #256765 #384 from eea/…
Browse files Browse the repository at this point in the history
…popper
  • Loading branch information
ichim-david authored Aug 29, 2023
2 parents 8802322 + 005f2be commit ee69ca2
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions src/ui/Popup/Popup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function Popup(props) {
const triggerRef = useRef(null);
const popupRef = useRef(null);
const [isOpen, setIsOpen] = useState(false);

const options = {
placement: positionsMapping[props.position] || 'bottom-end',
strategy: props.positionFixed || 'absolute',
Expand All @@ -33,12 +32,19 @@ function Popup(props) {
],
};

const { styles, attributes } = usePopper(
const { styles, attributes, update } = usePopper(
triggerRef.current,
popupRef.current,
options,
);

useEffect(() => {
const updatePlacement = async () => {
if (typeof update === 'function') await update();
};
updatePlacement();
}, [isOpen, update]);

const handleClickOutside = (event) => {
if (
popupRef.current &&
Expand Down Expand Up @@ -72,7 +78,6 @@ function Popup(props) {
const { trigger, className, size, position, basic, content, on } = props;

const onEvent = 'on' + on.charAt(0).toUpperCase() + on.slice(1);

return (
<React.Fragment>
{trigger && (
Expand All @@ -90,20 +95,22 @@ function Popup(props) {
{...attributes.popper}
>
{isOpen && <EventStack name="keydown" on={closeOnEscape} />}
<React.Fragment>
<div
className={cx(
'ui popup transition',
className,
size,
position,
basic ? 'basic' : '',
isOpen ? 'visible' : '',
)}
>
{content}
</div>
</React.Fragment>
{isOpen && (
<React.Fragment>
<div
className={cx(
'ui popup transition',
className,
size,
position,
basic ? 'basic' : '',
'visible',
)}
>
{content}
</div>
</React.Fragment>
)}
</div>
</React.Fragment>
);
Expand Down

0 comments on commit ee69ca2

Please sign in to comment.