Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-5138: The header in content edit view is displayed incorrectly when scrolling #714

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/bundle/Resources/public/js/scripts/edit.header.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(function (global, doc) {
const SCROLL_POSITION_TO_FIT = 50;
const HEADER_RIGHT_MARGIN = 50;
const MIN_HEIGHT_DIFF_FOR_FITTING_HEADER = 150;
const headerNode = doc.querySelector('.ibexa-edit-header');
const contentNode = doc.querySelector('.ibexa-edit-content');
Expand All @@ -10,6 +11,17 @@

const { height: expandedHeaderHeight } = headerNode.getBoundingClientRect();
const scrolledContent = doc.querySelector('.ibexa-edit-content > :first-child');
const fitEllipsizedTitle = () => {
const titleNode = headerNode.querySelector('.ibexa-edit-header__name--ellipsized');
const firstMenuEntryNode = headerNode.querySelector('.ibexa-context-menu .ibexa-context-menu__item');
const { left: titleNodeLeft, width: titleNodeWidth } = titleNode.getBoundingClientRect();
const { left: firstMenuEntryNodeLeft } = firstMenuEntryNode.getBoundingClientRect();
const titleNodeWidthNew = firstMenuEntryNodeLeft - titleNodeLeft - HEADER_RIGHT_MARGIN;

if (titleNodeWidth > titleNodeWidthNew) {
titleNode.style.width = `${titleNodeWidthNew}px`;
}
};
const fitHeader = (event) => {
const { height: formHeight } = scrolledContent.getBoundingClientRect();
const contentHeightWithExpandedHeader = formHeight + expandedHeaderHeight;
Expand All @@ -23,6 +35,10 @@
const shouldHeaderBeSlim = scrollTop > SCROLL_POSITION_TO_FIT;

headerNode.classList.toggle('ibexa-edit-header--slim', shouldHeaderBeSlim);

if (shouldHeaderBeSlim) {
Copy link
Contributor

@tischsoic tischsoic Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this solution take into account really long words, which can be problematic also when header is not slim?

fitEllipsizedTitle();
}
};

contentNode.addEventListener('scroll', fitHeader, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@

middleEllipsisContainers.forEach((middleEllipsisContainer) => {
const partStart = middleEllipsisContainer.querySelector('.ibexa-middle-ellipsis__name--start');
const isEllipsized = partStart.scrollWidth > partStart.offsetWidth;

middleEllipsisContainer.classList.toggle('ibexa-middle-ellipsis--ellipsized', partStart.scrollWidth > partStart.offsetWidth);
if (!isEllipsized) {
middleEllipsisContainer.dataset.bsOriginalTitle = '';
} else {
const partStartContentNode = partStart.querySelector('.ibexa-middle-ellipsis__name-ellipsized');

baseElement.dataset.bsOriginalTitle = partStartContentNode.innerHTML;
}

middleEllipsisContainer.classList.toggle('ibexa-middle-ellipsis--ellipsized', isEllipsized);
ibexa.helpers.tooltips.parse(middleEllipsisContainer);

resizeEllipsisObserver.observe(middleEllipsisContainer);
Expand Down
24 changes: 24 additions & 0 deletions src/bundle/Resources/public/scss/_edit-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
display: flex;
}

&__name {
&--ellipsized {
display: none;
}

&--full {
display: inline-block;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
}
}

&__row {
display: flex;
flex-wrap: nowrap;
Expand Down Expand Up @@ -135,6 +148,7 @@
.ibexa-edit-header {
&__row {
&--bottom {
z-index: 1;
margin-top: calculateRem(-45px);
}
}
Expand Down Expand Up @@ -166,6 +180,16 @@
&__title {
min-height: calculateRem(34px);
}

&__name {
&--ellipsized {
display: inline-block;
}

&--full {
display: none;
}
}
}

.ibexa-autosave {
Expand Down
6 changes: 5 additions & 1 deletion src/bundle/Resources/public/scss/_middle-ellipsis.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.ibexa-middle-ellipsis {
position: relative;
display: inline-flex;
max-width: 100%;

Expand All @@ -11,7 +12,7 @@

&--end {
margin-left: calculateRem(-10px);
width: initial;
width: 100%;
}
}

Expand All @@ -22,6 +23,9 @@
}

&__separator {
position: absolute;
left: 50%;
transform: translateX(-50%);
display: none;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@
<div class="ibexa-edit-header__row ibexa-edit-header__row--bottom">
<div class="ibexa-edit-header__column ibexa-edit-header__column--left">
<h1 class="ibexa-edit-header__title">
{{ title }}
<span class="ibexa-edit-header__name ibexa-edit-header__name--ellipsized">
{{ include('@ibexadesign/ui/component/middle_ellipsis/middle_ellipsis.html.twig', {
name: title,
}) }}
</span>
<span class="ibexa-edit-header__name ibexa-edit-header__name--full">
{{ title }}
</span>
{% if (description is defined and description|length) or content is defined and content is not null %}
<div
class="ibexa-edit-header__tooltip"
Expand Down