Skip to content

Commit

Permalink
fix(popup): ref error and make sure that all .popup-container .popup …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
ichim-david committed Aug 8, 2023
1 parent 6134272 commit 4435c1f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
25 changes: 20 additions & 5 deletions src/ui/Popup/Popup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -82,11 +94,14 @@ class Popup extends React.Component {
const onEvent = 'on' + event.charAt(0).toUpperCase() + event.slice(1);
return (
<React.Fragment>
{trigger &&
React.cloneElement(trigger, {
[onEvent]: this.togglePopup,
ref: this.triggerRef,
})}
{trigger && (
<div className="popup-trigger" ref={this.triggerRef}>
{React.cloneElement(trigger, {
[onEvent]: this.togglePopup,
ref: this.triggerRef,
})}
</div>
)}

<div className="popup-container" ref={this.popupRef}>
{this.state.isOpen && (
Expand Down
2 changes: 1 addition & 1 deletion src/ui/Popup/Popup.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default {
};

export const ButtonPopup = (args) => (
<Segment placeholder>
<Segment placeholder className={'flex-row flex-items-center'}>
<Popup
{...args}
trigger={
Expand Down
1 change: 0 additions & 1 deletion theme/themes/eea/extras/banner.less
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
/*Share Popup*/

.ui.popup.share-popup {
position: initial; // without position initial popper cannot correctly place popup
min-width: @sharePopupMinWidth;
padding: @sharePopupPadding;
filter: @sharePopupFilter;
Expand Down
9 changes: 9 additions & 0 deletions theme/themes/eea/globals/utilities.less
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ h1, h2, h3, h4, h5, h6, p, span, .header {
z-index: 0;
}

/* Layout */
// Flexbox
.d-flex { display: flex !important; }
.flex-row { flex-direction: row !important; }
.flex-items-start { align-items: flex-start !important; }
.flex-items-end { align-items: flex-end !important; }
.flex-items-center { align-items: center !important; }

// Columns
each(range(2, 6), {
.has--@{value}--columns {
columns: @value;
}
});

// Text
.text-left,
.has--text--left,
Expand Down
4 changes: 4 additions & 0 deletions theme/themes/eea/modules/popup.overrides
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@
.with-popup {
cursor: @cursor;
}

.popup-container .popup {
position: initial; // without position initial popper cannot correctly place popup
}

0 comments on commit 4435c1f

Please sign in to comment.