Skip to content

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

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

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions packages/main/src/components/ObjectPage/ObjectPage.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
);
Expand All @@ -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>
);
Expand Down Expand Up @@ -311,7 +316,7 @@ describe('ObjectPage', () => {
headerTitle={DPTitle}
headerContent={DPContent}
mode={ObjectPageMode.IconTabBar}
style={{ height: '100vh' }}
style={{ height: '100vh', scrollBehavior: 'auto' }}
>
{OPContent}
</ObjectPage>
Expand Down Expand Up @@ -341,7 +346,7 @@ describe('ObjectPage', () => {
headerContent={DPContent}
footer={Footer}
mode={ObjectPageMode.IconTabBar}
style={{ height: '100vh' }}
style={{ height: '100vh', scrollBehavior: 'auto' }}
>
{OPContent}
</ObjectPage>
Expand Down
3 changes: 3 additions & 0 deletions packages/main/src/components/ObjectPage/ObjectPage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 6 additions & 3 deletions packages/main/src/components/ObjectPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
};
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
Loading