From 4435c1fd10f81c9366955567fc1bc6a2c5364ba7 Mon Sep 17 00:00:00 2001 From: David Ichim Date: Tue, 8 Aug 2023 20:50:11 +0300 Subject: [PATCH] fix(popup): ref error and make sure that all .popup-container .popup get their position fixed - also ensure position is updated when placement is changed so that storybook example functions correctly when interacting with the position controls --- src/ui/Popup/Popup.jsx | 25 +++++++++++++++++++----- src/ui/Popup/Popup.stories.jsx | 2 +- theme/themes/eea/extras/banner.less | 1 - theme/themes/eea/globals/utilities.less | 9 +++++++++ theme/themes/eea/modules/popup.overrides | 4 ++++ 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/ui/Popup/Popup.jsx b/src/ui/Popup/Popup.jsx index 00d88042ed..2deb320c27 100644 --- a/src/ui/Popup/Popup.jsx +++ b/src/ui/Popup/Popup.jsx @@ -54,6 +54,18 @@ class Popup extends React.Component { this.popper && this.popper.destroy(); } + componentWillUpdate(nextProps, nextState, nextContext) { + const position = nextProps.position; + if ( + position && + this.popper.state.placement !== positionsMapping[position] + ) { + this.popper.setOptions({ + placement: positionsMapping[position] || 'bottom-end', + }); + } + } + togglePopup() { this.setState( (state) => { @@ -82,11 +94,14 @@ class Popup extends React.Component { const onEvent = 'on' + event.charAt(0).toUpperCase() + event.slice(1); return ( - {trigger && - React.cloneElement(trigger, { - [onEvent]: this.togglePopup, - ref: this.triggerRef, - })} + {trigger && ( +
+ {React.cloneElement(trigger, { + [onEvent]: this.togglePopup, + ref: this.triggerRef, + })} +
+ )}
{this.state.isOpen && ( diff --git a/src/ui/Popup/Popup.stories.jsx b/src/ui/Popup/Popup.stories.jsx index e9a721cb4b..0310a4d454 100644 --- a/src/ui/Popup/Popup.stories.jsx +++ b/src/ui/Popup/Popup.stories.jsx @@ -59,7 +59,7 @@ export default { }; export const ButtonPopup = (args) => ( - +