Skip to content

Commit 6fc5199

Browse files
authored
fix(ObjectPage): support section selection in iframe (#6535) (#6542)
Also fixes two flaky ObjectPage tests
1 parent 61deb76 commit 6fc5199

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ describe('ObjectPage', () => {
242242
it('scroll to sections - default mode', () => {
243243
document.body.style.margin = '0px';
244244
cy.mount(
245-
<ObjectPage headerTitle={DPTitle} headerContent={DPContent}>
245+
<ObjectPage headerTitle={DPTitle} headerContent={DPContent} style={{ height: '100vh', scrollBehavior: 'auto' }}>
246246
{OPContent}
247247
</ObjectPage>
248248
);
@@ -267,7 +267,12 @@ describe('ObjectPage', () => {
267267
cy.findByText('Job Relationship').should('be.visible');
268268

269269
cy.mount(
270-
<ObjectPage headerTitle={DPTitle} headerContent={DPContent} footer={Footer}>
270+
<ObjectPage
271+
headerTitle={DPTitle}
272+
headerContent={DPContent}
273+
footer={Footer}
274+
style={{ height: '100vh', scrollBehavior: 'auto' }}
275+
>
271276
{OPContent}
272277
</ObjectPage>
273278
);
@@ -311,7 +316,7 @@ describe('ObjectPage', () => {
311316
headerTitle={DPTitle}
312317
headerContent={DPContent}
313318
mode={ObjectPageMode.IconTabBar}
314-
style={{ height: '100vh' }}
319+
style={{ height: '100vh', scrollBehavior: 'auto' }}
315320
>
316321
{OPContent}
317322
</ObjectPage>
@@ -341,7 +346,7 @@ describe('ObjectPage', () => {
341346
headerContent={DPContent}
342347
footer={Footer}
343348
mode={ObjectPageMode.IconTabBar}
344-
style={{ height: '100vh' }}
349+
style={{ height: '100vh', scrollBehavior: 'auto' }}
345350
>
346351
{OPContent}
347352
</ObjectPage>

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

+3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import { DynamicPageTitle } from '../DynamicPageTitle';
66
import { DynamicPageHeader } from '../DynamicPageHeader';
77
import { ObjectPageSection } from '../ObjectPageSection';
88
import { ObjectPageSubSection } from '../ObjectPageSubSection';
9+
import { MessageStrip } from '@ui5/webcomponents-react';
910

1011
<Meta of={ComponentStories} />
1112

1213
<DocsHeader subComponents={['DynamicPageTitle', 'DynamicPageHeader', 'ObjectPageSection', 'ObjectPageSubSection']} />
1314

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

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

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

+3
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

+6-3
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,10 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
319319
TAB_CONTAINER_HEADER_HEIGHT +
320320
(headerPinned && !headerCollapsed ? headerContentHeight : 0) +
321321
'px';
322-
section.focus();
323-
section.scrollIntoView({ behavior: 'smooth' });
322+
if (isSubSection) {
323+
section.focus();
324+
}
325+
section.scrollIntoView();
324326
section.style.scrollMarginBlockStart = '0px';
325327
}
326328
};
@@ -330,7 +332,7 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
330332
return;
331333
}
332334
if (firstSectionId === sectionId) {
333-
objectPageRef.current?.scrollTo({ top: 0, behavior: 'smooth' });
335+
objectPageRef.current?.scrollTo({ top: 0 });
334336
} else {
335337
scrollToSectionById(sectionId);
336338
}
@@ -766,6 +768,7 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
766768
style={objectPageStyles}
767769
ref={componentRef}
768770
onScroll={onObjectPageScroll}
771+
data-in-iframe={window && window.self !== window.top}
769772
{...propsWithoutOmitted}
770773
>
771774
<header

0 commit comments

Comments
 (0)