Skip to content

Commit 6b43b58

Browse files
authored
refactor(ObjectPageTitle): replace :has (#7044)
Fixes #6979
1 parent e3679b9 commit 6b43b58

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

packages/main/src/components/ObjectPageTitle/ObjectPageTitle.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
}
128128
}
129129

130-
.actionsSpacer {
130+
.actionsSeparator {
131131
flex-shrink: 0;
132132
height: var(--_ui5_dynamic_page_title_actions_separator_height);
133133
width: 0.0625rem;

packages/main/src/components/ObjectPageTitle/index.tsx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,30 +165,27 @@ const ObjectPageTitle = forwardRef<HTMLDivElement, ObjectPageTitlePropTypes>((pr
165165
useEffect(() => {
166166
const toolbarContainer = toolbarContainerRef.current;
167167

168-
const observer = new MutationObserver(([toolbarContainerMutation]) => {
169-
if (toolbarContainerMutation.type === 'childList') {
170-
const navigationToolbar: ToolbarDomRef | undefined = (
171-
toolbarContainerMutation.target as HTMLDivElement
172-
).querySelector(':has(> :nth-last-child(n + 2)) > [ui5-toolbar]:last-child');
173-
if (navigationToolbar?.children) {
174-
Array.from(navigationToolbar.children).forEach((item) => {
168+
const updateNavigationToolbar = (container: HTMLDivElement) => {
169+
if (container.children.length >= 2) {
170+
const lastChild = container.lastElementChild as ToolbarDomRef;
171+
if (lastChild && lastChild.matches('[ui5-toolbar]')) {
172+
Array.from(lastChild.children).forEach((item) => {
175173
item.setAttribute('overflow-priority', 'NeverOverflow');
176174
});
177175
}
178176
}
177+
};
178+
179+
const observer = new MutationObserver(([toolbarContainerMutation]) => {
180+
if (toolbarContainerMutation.type === 'childList') {
181+
updateNavigationToolbar(toolbarContainerMutation.target as HTMLDivElement);
182+
}
179183
});
180184

181185
const config = { childList: true, subtree: true };
182186

183187
if (toolbarContainer) {
184-
const navigationToolbar: ToolbarDomRef | undefined = toolbarContainer.querySelector(
185-
':has(> :nth-last-child(n + 2)) > [ui5-toolbar]:last-child'
186-
);
187-
if (navigationToolbar?.children) {
188-
Array.from(navigationToolbar.children).forEach((item) => {
189-
item.setAttribute('overflow-priority', 'NeverOverflow');
190-
});
191-
}
188+
updateNavigationToolbar(toolbarContainer);
192189
observer.observe(toolbarContainer, config);
193190
}
194191

@@ -243,7 +240,7 @@ const ObjectPageTitle = forwardRef<HTMLDivElement, ObjectPageTitlePropTypes>((pr
243240
{actionsBar}
244241
{!showNavigationInTopArea && actionsBar && navigationBar && (
245242
<div
246-
className={classNames.actionsSpacer}
243+
className={classNames.actionsSeparator}
247244
data-component-name="ObjectPageTitleActionsSeparator"
248245
aria-hidden
249246
/>

0 commit comments

Comments
 (0)