Skip to content

Commit 2ef456b

Browse files
OstafinLtischsoic
andauthored
IBX-8824: The popup for custom tags with multiple fields is not scrollable (#183)
Co-authored-by: tischsoic <[email protected]>
1 parent c237fd7 commit 2ef456b

File tree

6 files changed

+67
-9
lines changed

6 files changed

+67
-9
lines changed

src/bundle/Resources/public/js/CKEditor/custom-tags/block-custom-tag/custom-tag-ui.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
22
import clickOutsideHandler from '@ckeditor/ckeditor5-ui/src/bindings/clickoutsidehandler';
33
import ClickObserver from '@ckeditor/ckeditor5-engine/src/view/observer/clickobserver';
44

5+
import { setPanelContentMaxHeight } from '../helpers/panel-helper';
56
import IbexaCustomTagFormView from '../ui/custom-tag-form-view';
67
import IbexaCustomTagAttributesView from '../ui/custom-tag-attributes-view';
78
import IbexaButtonView from '../../common/button-view/button-view';
@@ -18,6 +19,14 @@ class IbexaCustomTagUI extends Plugin {
1819
this.addCustomTag = this.addCustomTag.bind(this);
1920

2021
this.isNew = false;
22+
23+
let timeoutId = null;
24+
this.listenTo(this.balloon.view, 'change:top', () => {
25+
clearTimeout(timeoutId);
26+
timeoutId = setTimeout(() => {
27+
setPanelContentMaxHeight(this.balloon.view);
28+
}, 0);
29+
});
2130
}
2231

2332
isCustomTagSelected(eventData) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const setPanelContentMaxHeight = (balloonView) => {
2+
const MIN_HEIGHT_VALUE = 100;
3+
const MARGIN = 50;
4+
const { innerHeight: windowHeight } = window;
5+
const { element: panelNode } = balloonView;
6+
const panelHeader = panelNode.querySelector('.ibexa-custom-tag-panel-header');
7+
const panelContent = panelNode.querySelector('.ibexa-custom-tag-panel-content');
8+
const panelFooter = panelNode.querySelector('.ibexa-custom-tag-panel-footer');
9+
10+
if (!panelContent) {
11+
return;
12+
}
13+
14+
const isBalloonAbovePivot = panelNode.classList.contains('ck-balloon-panel_arrow_s');
15+
const panelInitialHeight = panelNode.offsetHeight;
16+
const panelTopPosition = parseInt(panelNode.style.top, 10);
17+
const panelHeaderHeight = panelHeader?.offsetHeight ?? 0;
18+
const panelFooterHeight = panelFooter?.offsetHeight ?? 0;
19+
const maxHeightValue = isBalloonAbovePivot
20+
? panelInitialHeight + panelTopPosition - panelHeaderHeight - panelFooterHeight - MARGIN
21+
: windowHeight - panelTopPosition - panelHeaderHeight - panelFooterHeight - MARGIN;
22+
const panelMaxHeight = maxHeightValue < MIN_HEIGHT_VALUE ? MIN_HEIGHT_VALUE : maxHeightValue;
23+
24+
panelContent.style.maxHeight = `${panelMaxHeight}px`;
25+
26+
if (isBalloonAbovePivot) {
27+
const panelNewHeight = panelNode.offsetHeight;
28+
const panelHeightChange = panelInitialHeight - panelNewHeight;
29+
const panelNewTopPosition = panelTopPosition + panelHeightChange;
30+
31+
panelNode.style.top = `${panelNewTopPosition}px`;
32+
}
33+
};
34+
35+
export { setPanelContentMaxHeight };

src/bundle/Resources/public/js/CKEditor/custom-tags/ui/custom-tag-attributes-view.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ class IbexaCustomTagAttributesView extends View {
3333

3434
buttonView.delegate('execute').to(this, 'edit-attributes');
3535

36+
const items = [];
3637
const children = [
3738
{
3839
tag: 'div',
3940
attributes: {
40-
class: 'ibexa-custom-tag-attributes__header',
41+
class: 'ibexa-custom-tag-attributes__header ibexa-custom-tag-panel-header',
4142
},
4243
children: [
4344
{
@@ -63,7 +64,7 @@ class IbexaCustomTagAttributesView extends View {
6364
const getValueLabelMethods = window.ibexa.richText.CKEditor.customTags?.getValueLabelMethods || {};
6465
const valueLabel = getValueLabelMethods[name] && value !== '-' ? getValueLabelMethods[name](value, config) : value;
6566

66-
children.push({
67+
items.push({
6768
tag: 'div',
6869
attributes: {
6970
class: 'ibexa-custom-tag-attributes__item',
@@ -87,6 +88,14 @@ class IbexaCustomTagAttributesView extends View {
8788
});
8889
});
8990

91+
children.push({
92+
tag: 'div',
93+
attributes: {
94+
class: 'ibexa-custom-tag-attributes__items ibexa-custom-tag-panel-content',
95+
},
96+
children: items,
97+
});
98+
9099
return children;
91100
}
92101
}

src/bundle/Resources/public/js/CKEditor/custom-tags/ui/custom-tag-form-view.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class IbexaCustomTagFormView extends View {
121121
{
122122
tag: 'div',
123123
attributes: {
124-
class: 'ibexa-ckeditor-balloon-form__header',
124+
class: 'ibexa-ckeditor-balloon-form__header ibexa-custom-tag-panel-header',
125125
},
126126
children: [label],
127127
},
@@ -134,14 +134,14 @@ class IbexaCustomTagFormView extends View {
134134
{
135135
tag: 'div',
136136
attributes: {
137-
class: 'ibexa-ckeditor-balloon-form__fields',
137+
class: 'ibexa-ckeditor-balloon-form__fields ibexa-custom-tag-panel-content',
138138
},
139139
children: this.children,
140140
},
141141
{
142142
tag: 'div',
143143
attributes: {
144-
class: 'ibexa-ckeditor-balloon-form__actions',
144+
class: 'ibexa-ckeditor-balloon-form__actions ibexa-custom-tag-panel-footer',
145145
},
146146
children: [this.saveButtonView, this.cancelButtonView],
147147
},

src/bundle/Resources/public/scss/_balloon-form.scss

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
.ck.ck-reset_all {
22
.ibexa-ckeditor-balloon-form {
3-
padding: 0 calculateRem(16px);
3+
position: relative;
44

55
&__header {
66
border-top-left-radius: $ibexa-border-radius;
77
border-top-right-radius: $ibexa-border-radius;
8-
padding: calculateRem(2px) 0;
8+
padding: calculateRem(2px) calculateRem(16px);
99
font-weight: bold;
1010
}
1111

1212
&__fields {
13-
padding: calculateRem(8px) 0;
13+
overflow: auto;
14+
padding: calculateRem(8px) calculateRem(16px);
1415

1516
&--attributes {
1617
border-bottom: calculateRem(1px) solid $ibexa-color-light;
@@ -135,7 +136,7 @@
135136
}
136137

137138
&__actions {
138-
padding: 0 0 calculateRem(16px);
139+
padding: calculateRem(8px) calculateRem(16px);
139140
}
140141
}
141142

src/bundle/Resources/public/scss/_custom-tag-attributes.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
font-weight: bold;
1818
}
1919

20+
&__items {
21+
overflow: auto;
22+
}
23+
2024
&__item {
2125
padding: calculateRem(8px) calculateRem(16px);
2226
}

0 commit comments

Comments
 (0)