Skip to content

Commit 359fe49

Browse files
authored
fix(ui5-dynamic-page): hide pin button on mobile devices (#13335)
The pin/unpin button is now automatically hidden on mobile devices in accordance with SAP Fiori guidelines, which state that the Pin Header action should not be provided on small screens as the pinned header would take up too much screen real estate. - Additionally, introduced PAGE_HEIGHT constant in DynamicPage.mobile.cy to reduce repetition of hardcoded "600px" values. Fixes #13320
1 parent 0b16434 commit 359fe49

3 files changed

Lines changed: 40 additions & 11 deletions

File tree

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

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import DynamicPage from "../../src/DynamicPage.js";
22
import DynamicPageTitle from "../../src/DynamicPageTitle.js";
33
import DynamicPageHeader from "../../src/DynamicPageHeader.js";
44

5+
const PAGE_HEIGHT = "600px";
6+
57
describe("DynamicPage Mobile Behaviour", () => {
68
beforeEach(() => {
79
cy.ui5SimulateDevice("phone");
810
});
911
it("should display snapped title on mobile when snappedTitleOnMobile slot has content and header is snapped", () => {
1012
cy.mount(
11-
<DynamicPage style={{ height: "600px" }}>
13+
<DynamicPage style={{ height: PAGE_HEIGHT }}>
1214
<DynamicPageTitle slot="titleArea">
1315
<div slot="heading">Page Title</div>
1416
<div slot="snappedTitleOnMobile">Mobile Snapped Title</div>
@@ -30,7 +32,7 @@ describe("DynamicPage Mobile Behaviour", () => {
3032

3133
it("the header content should not be rendered when snappedTitleOnMobile content is present", () => {
3234
cy.mount(
33-
<DynamicPage style={{ height: "600px" }}>
35+
<DynamicPage style={{ height: PAGE_HEIGHT }}>
3436
<DynamicPageTitle slot="titleArea">
3537
<div slot="heading">Page Title</div>
3638
<div slot="snappedTitleOnMobile">Mobile Snapped Title</div>
@@ -60,7 +62,7 @@ describe("DynamicPage Mobile Behaviour", () => {
6062

6163
it("should not display snapped title on mobile when snappedTitleOnMobile slot is empty", () => {
6264
cy.mount(
63-
<DynamicPage style={{ height: "600px" }}>
65+
<DynamicPage style={{ height: PAGE_HEIGHT }}>
6466
<DynamicPageTitle slot="titleArea">
6567
<div slot="heading">Page Title</div>
6668
<div slot="snappedTitleOnMobile">Mobile Snapped Title</div>
@@ -94,7 +96,7 @@ describe("DynamicPage Mobile Behaviour", () => {
9496

9597
it("should expand the header when clicked on the snapped title on mobile", () => {
9698
cy.mount(
97-
<DynamicPage style={{ height: "600px" }}>
99+
<DynamicPage style={{ height: PAGE_HEIGHT }}>
98100
<DynamicPageTitle slot="titleArea">
99101
<div slot="heading">Page Title</div>
100102
<div slot="snappedTitleOnMobile">Mobile Snapped Title</div>
@@ -122,7 +124,7 @@ describe("DynamicPage Mobile Behaviour", () => {
122124

123125
it("should not display snapped title on mobile when header is not snapped", () => {
124126
cy.mount(
125-
<DynamicPage style={{ height: "600px" }}>
127+
<DynamicPage style={{ height: PAGE_HEIGHT }}>
126128
<DynamicPageTitle slot="titleArea">
127129
<div slot="heading">Page Title</div>
128130
<div slot="snappedTitleOnMobile">Mobile Snapped Title</div>
@@ -142,9 +144,9 @@ describe("DynamicPage Mobile Behaviour", () => {
142144
cy.contains("Mobile Snapped Title").should("not.be.visible");
143145
});
144146

145-
it("should focus the title focus area when header action is clicked to snap the header", () => {
147+
it("should focus the title focus area when header action is clicked to snap the header", () => {
146148
cy.mount(
147-
<DynamicPage style={{ height: "600px" }}>
149+
<DynamicPage style={{ height: PAGE_HEIGHT }}>
148150
<DynamicPageTitle slot="titleArea">
149151
<div slot="heading">Page Title</div>
150152
<div slot="snappedTitleOnMobile">Mobile Snapped Title</div>
@@ -160,21 +162,44 @@ describe("DynamicPage Mobile Behaviour", () => {
160162

161163
cy.get("[ui5-dynamic-page]")
162164
.invoke("prop", "headerSnapped", false);
163-
165+
164166
cy.get("[ui5-dynamic-page]")
165167
.shadow()
166168
.find("ui5-dynamic-page-header-actions")
167169
.shadow()
168170
.find(".ui5-dynamic-page-header-action")
169171
.first()
170172
.click();
171-
173+
172174
cy.get("[ui5-dynamic-page]")
173175
.should("have.prop", "headerSnapped", true);
174-
176+
175177
cy.get("[ui5-dynamic-page-title]")
176178
.shadow()
177179
.find(".ui5-dynamic-page-title-focus-area")
178180
.should("be.focused");
179181
});
182+
183+
it("should not display pin button on mobile devices", () => {
184+
cy.mount(
185+
<DynamicPage style={{ height: PAGE_HEIGHT }}>
186+
<DynamicPageTitle slot="titleArea">
187+
<div slot="heading">Page Title</div>
188+
</DynamicPageTitle>
189+
<DynamicPageHeader slot="headerArea">
190+
<div>Header Content</div>
191+
</DynamicPageHeader>
192+
<div style={{ height: "1000px" }}>
193+
Page content with enough height to enable scrolling
194+
</div>
195+
</DynamicPage>
196+
);
197+
198+
cy.get("[ui5-dynamic-page]")
199+
.shadow()
200+
.find("ui5-dynamic-page-header-actions")
201+
.shadow()
202+
.find(".ui5-dynamic-page-header-action-pin")
203+
.should("not.exist");
204+
});
180205
});

packages/fiori/src/DynamicPage.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ class DynamicPage extends UI5Element {
284284
return this.hasHeading ? this._headerLabel : undefined;
285285
}
286286

287+
get _hidePinButton() {
288+
return this.hidePinButton || isPhone();
289+
}
290+
287291
/**
288292
* Defines if the header is snapped.
289293
*

packages/fiori/src/DynamicPageTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function headerActions(this: DynamicPage) {
6161
<DynamicPageHeaderActions
6262
snapped={this.headerSnapped}
6363
pinned={this.headerPinned}
64-
hidePinButton={this.hidePinButton}
64+
hidePinButton={this._hidePinButton}
6565
onui5-expand-button-click={this.onExpandClick}
6666
onui5-pin-button-click={this.onPinClick}
6767
onui5-expand-button-hover-in={this.onExpandHoverIn}

0 commit comments

Comments
 (0)