Skip to content

Commit 7fdabb0

Browse files
authored
fix(ui5-dynamic-page): handle header-snapped attribute initialization (#13030)
The headerSnapped setter was called before scrollContainer was available, causing a null reference error. Now it defers DOM manipulation until the component is rendered. Fixes #13011
1 parent 603cb7a commit 7fdabb0

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

packages/fiori/cypress/specs/DynamicPage.cy.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,35 @@ describe("DynamicPage", () => {
4343
.should("have.prop", "headerPinned", false);
4444
});
4545

46+
it("renders correctly with initial header-snapped attribute", () => {
47+
cy.mount(
48+
<DynamicPage headerSnapped={true} style={{ height: "600px" }}>
49+
<DynamicPageTitle slot="titleArea">
50+
<div slot="heading">Page Title</div>
51+
<div slot="snappedHeading">Snapped Title</div>
52+
</DynamicPageTitle>
53+
<DynamicPageHeader slot="headerArea">
54+
<div>Header Content</div>
55+
</DynamicPageHeader>
56+
<div style={{ height: "1000px" }}>
57+
Page content with enough height to enable scrolling
58+
</div>
59+
</DynamicPage>
60+
);
61+
62+
cy.get("[ui5-dynamic-page]")
63+
.should("have.prop", "headerSnapped", true);
64+
65+
cy.get("[ui5-dynamic-page-title]")
66+
.should("have.prop", "snapped", true);
67+
68+
cy.get("[ui5-dynamic-page-header]")
69+
.should("have.prop", "_snapped", true);
70+
71+
cy.get("[slot='snappedHeading']")
72+
.should("be.visible");
73+
});
74+
4675
it("toggles the header-snapped state with 'headerSnapped' property", () => {
4776
cy.mount(
4877
<DynamicPage style={{ height: "600px" }}>

packages/fiori/src/DynamicPage.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,17 @@ class DynamicPage extends UI5Element {
292292
*/
293293
@property({ type: Boolean })
294294
set headerSnapped(snapped: boolean) {
295-
if (snapped !== this._headerSnapped) {
296-
this._toggleHeader();
295+
if (snapped === this._headerSnapped) {
296+
return;
297+
}
298+
299+
if (!this.scrollContainer) {
300+
this._headerSnapped = snapped;
301+
this.showHeaderInStickArea = snapped;
302+
return;
297303
}
304+
305+
this._toggleHeader();
298306
}
299307

300308
snapOnScroll() {

0 commit comments

Comments
 (0)