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

fix(ObjectPage): support section selection in iframe (#6535) #6542

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all 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
fix(ObjectPage): support section selection in iframe (#6535)
Also fixes two flaky ObjectPage tests
Lukas742 committed Oct 22, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit cbb017a246543463d705dccbcabd1ae747034b10
13 changes: 9 additions & 4 deletions packages/main/src/components/ObjectPage/ObjectPage.cy.tsx
Original file line number Diff line number Diff line change
@@ -242,7 +242,7 @@ describe('ObjectPage', () => {
it('scroll to sections - default mode', () => {
document.body.style.margin = '0px';
cy.mount(
<ObjectPage headerTitle={DPTitle} headerContent={DPContent}>
<ObjectPage headerTitle={DPTitle} headerContent={DPContent} style={{ height: '100vh', scrollBehavior: 'auto' }}>
{OPContent}
</ObjectPage>
);
@@ -267,7 +267,12 @@ describe('ObjectPage', () => {
cy.findByText('Job Relationship').should('be.visible');

cy.mount(
<ObjectPage headerTitle={DPTitle} headerContent={DPContent} footer={Footer}>
<ObjectPage
headerTitle={DPTitle}
headerContent={DPContent}
footer={Footer}
style={{ height: '100vh', scrollBehavior: 'auto' }}
>
{OPContent}
</ObjectPage>
);
@@ -311,7 +316,7 @@ describe('ObjectPage', () => {
headerTitle={DPTitle}
headerContent={DPContent}
mode={ObjectPageMode.IconTabBar}
style={{ height: '100vh' }}
style={{ height: '100vh', scrollBehavior: 'auto' }}
>
{OPContent}
</ObjectPage>
@@ -341,7 +346,7 @@ describe('ObjectPage', () => {
headerContent={DPContent}
footer={Footer}
mode={ObjectPageMode.IconTabBar}
style={{ height: '100vh' }}
style={{ height: '100vh', scrollBehavior: 'auto' }}
>
{OPContent}
</ObjectPage>
3 changes: 3 additions & 0 deletions packages/main/src/components/ObjectPage/ObjectPage.mdx
Original file line number Diff line number Diff line change
@@ -6,11 +6,14 @@ import { DynamicPageTitle } from '../DynamicPageTitle';
import { DynamicPageHeader } from '../DynamicPageHeader';
import { ObjectPageSection } from '../ObjectPageSection';
import { ObjectPageSubSection } from '../ObjectPageSubSection';
import { MessageStrip } from '@ui5/webcomponents-react';

<Meta of={ComponentStories} />

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

<MessageStrip hideCloseButton children={'In iframes, smooth scrolling is disabled!'} />

## Example

<Canvas of={ComponentStories.Default} />
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@
overflow-x: hidden;
overflow-y: auto;
scroll-behavior: smooth;
&[data-in-iframe='true'] {
scroll-behavior: auto;
}
section[id*='ObjectPageSection-'] > div[role='heading'] {
display: none;
}
9 changes: 6 additions & 3 deletions packages/main/src/components/ObjectPage/index.tsx
Original file line number Diff line number Diff line change
@@ -319,8 +319,10 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
TAB_CONTAINER_HEADER_HEIGHT +
(headerPinned && !headerCollapsed ? headerContentHeight : 0) +
'px';
section.focus();
section.scrollIntoView({ behavior: 'smooth' });
if (isSubSection) {
section.focus();
}
section.scrollIntoView();
section.style.scrollMarginBlockStart = '0px';
}
};
@@ -330,7 +332,7 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
return;
}
if (firstSectionId === sectionId) {
objectPageRef.current?.scrollTo({ top: 0, behavior: 'smooth' });
objectPageRef.current?.scrollTo({ top: 0 });
} else {
scrollToSectionById(sectionId);
}
@@ -766,6 +768,7 @@ const ObjectPage = forwardRef<HTMLDivElement, ObjectPagePropTypes>((props, ref)
style={objectPageStyles}
ref={componentRef}
onScroll={onObjectPageScroll}
data-in-iframe={window && window.self !== window.top}
{...propsWithoutOmitted}
>
<header
Loading