Skip to content

Commit ca82fcb

Browse files
authored
fix(ObjectPage): support section selection in iframe (#6535)
Also fixes two flaky ObjectPage tests
1 parent 9ab8b46 commit ca82fcb

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

packages/main/src/components/ObjectPage/ObjectPage.cy.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ describe('ObjectPage', () => {
259259
it('scroll to sections - default mode', () => {
260260
document.body.style.margin = '0px';
261261
cy.mount(
262-
<ObjectPage titleArea={DPTitle} headerArea={DPContent}>
262+
<ObjectPage titleArea={DPTitle} headerArea={DPContent} style={{ height: '100vh', scrollBehavior: 'auto' }}>
263263
{OPContent}
264264
</ObjectPage>
265265
);
@@ -287,7 +287,12 @@ describe('ObjectPage', () => {
287287
cy.findByText('Job Relationship').should('be.visible');
288288

289289
cy.mount(
290-
<ObjectPage titleArea={DPTitle} headerArea={DPContent} footerArea={Footer}>
290+
<ObjectPage
291+
titleArea={DPTitle}
292+
headerArea={DPContent}
293+
footerArea={Footer}
294+
style={{ height: '100vh', scrollBehavior: 'auto' }}
295+
>
291296
{OPContent}
292297
</ObjectPage>
293298
);
@@ -331,7 +336,7 @@ describe('ObjectPage', () => {
331336
titleArea={DPTitle}
332337
headerArea={DPContent}
333338
mode={ObjectPageMode.IconTabBar}
334-
style={{ height: '100vh' }}
339+
style={{ height: '100vh', scrollBehavior: 'auto' }}
335340
>
336341
{OPContent}
337342
</ObjectPage>
@@ -361,7 +366,7 @@ describe('ObjectPage', () => {
361366
headerArea={DPContent}
362367
footerArea={Footer}
363368
mode={ObjectPageMode.IconTabBar}
364-
style={{ height: '100vh' }}
369+
style={{ height: '100vh', scrollBehavior: 'auto' }}
365370
>
366371
{OPContent}
367372
</ObjectPage>

packages/main/src/components/ObjectPage/ObjectPage.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ import { ObjectPageHeader } from '../ObjectPageHeader';
77
import { ObjectPageSection } from '../ObjectPageSection';
88
import { ObjectPageSubSection } from '../ObjectPageSubSection';
99
import { CodeBlock } from '@sb/components/DomRefTable';
10+
import { MessageStrip } from '@ui5/webcomponents-react';
1011

1112
<Meta of={ComponentStories} />
1213

1314
<DocsHeader subComponents={['ObjectPageTitle', 'ObjectPageHeader', 'ObjectPageSection', 'ObjectPageSubSection']} />
1415

16+
<MessageStrip hideCloseButton children={'In iframes, smooth scrolling is disabled!'} />
17+
1518
## Example
1619

1720
<Canvas of={ComponentStories.Default} />

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
overflow-x: hidden;
1717
overflow-y: auto;
1818
scroll-behavior: smooth;
19+
&[data-in-iframe='true'] {
20+
scroll-behavior: auto;
21+
}
1922
section[id*='ObjectPageSection-'] > div[role='heading'] {
2023
display: none;
2124
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,10 @@ const ObjectPage = forwardRef<ObjectPageDomRef, ObjectPagePropTypes>((props, ref
334334
TAB_CONTAINER_HEADER_HEIGHT +
335335
(headerPinned && !headerCollapsed ? headerContentHeight : 0) +
336336
'px';
337-
section.focus();
338-
section.scrollIntoView({ behavior: 'smooth' });
337+
if (isSubSection) {
338+
section.focus();
339+
}
340+
section.scrollIntoView();
339341
section.style.scrollMarginBlockStart = '0px';
340342
}
341343
};
@@ -345,7 +347,7 @@ const ObjectPage = forwardRef<ObjectPageDomRef, ObjectPagePropTypes>((props, ref
345347
return;
346348
}
347349
if (firstSectionId === sectionId) {
348-
objectPageRef.current?.scrollTo({ top: 0, behavior: 'smooth' });
350+
objectPageRef.current?.scrollTo({ top: 0 });
349351
} else {
350352
scrollToSectionById(sectionId);
351353
}
@@ -729,6 +731,7 @@ const ObjectPage = forwardRef<ObjectPageDomRef, ObjectPagePropTypes>((props, ref
729731
style={objectPageStyles}
730732
ref={componentRef}
731733
onScroll={onObjectPageScroll}
734+
data-in-iframe={window && window.self !== window.top}
732735
{...propsWithoutOmitted}
733736
>
734737
<header

0 commit comments

Comments
 (0)