Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Commit

Permalink
Fix cropped nested expandable content in panels (#137)
Browse files Browse the repository at this point in the history
After finishing the panel expand animation or before the collapse
animation, the max height of the panel content wrapper is not
reset to their appropriate values.
This causes expandable content inside panels, such as nested panels.

Let’s do so, allowing the outer panel to react to changes in its
content height after expanding it.
  • Loading branch information
ang-zeyu committed Mar 30, 2020
1 parent e92ff64 commit 400d198
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/panels/MinimalPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
</div>
<transition @before-enter="beforeExpandMinimal"
@enter="duringExpand"
@after-enter="afterExpand"
@before-leave="beforeCollapse"
@leave="duringCollapse"
@after-leave="afterCollapseMinimal"
v-if="preloadBool || wasRetrieverLoaded"
Expand Down
2 changes: 2 additions & 0 deletions src/panels/NestedPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
</div>
<transition @before-enter="beforeExpand"
@enter="duringExpand"
@after-enter="afterExpand"
@before-leave="beforeCollapse"
@leave="duringCollapse"
v-if="preloadBool || wasRetrieverLoaded"
>
Expand Down
27 changes: 22 additions & 5 deletions src/panels/PanelBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ export default {
window.open(this.popupUrl);
},
setMaxHeight() {
// Don't play the transition for this case as the loading should feel 'instant'
if (this.expandedBool) {
this.$refs.panel.style.maxHeight = 'max-content';
return;
}

/*
Otherwise, since the vue transition is dependent on localExpanded, we have to manually
set our own transition end handlers here for the initial loading of the content.
*/
const onExpandDone = () => {
this.$refs.panel.style.maxHeight = 'max-content';
this.$refs.panel.removeEventListener('transitionend', onExpandDone);
};

this.$refs.panel.addEventListener('transitionend', onExpandDone);
this.$refs.panel.style.maxHeight = `${this.$refs.panel.scrollHeight}px`;
},
beforeExpand(el) {
Expand All @@ -130,6 +146,12 @@ export default {
jQuery("html").stop();
el.style.maxHeight = `${el.scrollHeight}px`;
},
afterExpand(el) {
el.style.maxHeight = 'max-content';
},
beforeCollapse(el) {
el.style.maxHeight = `${el.scrollHeight}px`;
},
duringCollapse(el) {
if (this.$el.getBoundingClientRect().top < 0) {
jQuery("html").animate({
Expand All @@ -154,9 +176,4 @@ export default {
this.wasRetrieverLoaded = this.localExpanded; // If it is expanded, load the retriever immediately.
this.localMinimized = this.minimizedBool;
},
mounted() {
// For this case, we want to set and calculate the maximum height only after the
// panel has been mounted.
if (this.expandedBool && !this.hasSrc) this.setMaxHeight();
}
};

0 comments on commit 400d198

Please sign in to comment.