Skip to content

Commit 4d75b7d

Browse files
authored
fix(ui5-breadcrumbs): show all items in popover on mobile (#11138)
The changes improve the mobile user experience by ensuring all navigation items are accessible from the dropdown menu when on mobile devices. Fixes: #9697
1 parent 5bc4d3e commit 4d75b7d

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Breadcrumbs from "../../src/Breadcrumbs.js";
2+
import BreadcrumbsItem from "../../src/BreadcrumbsItem.js";
3+
4+
describe("Breadcrumbs mobile behavior", () => {
5+
before(() => {
6+
cy.ui5SimulateDevice("phone");
7+
});
8+
9+
it("displays all items in the popover on mobile", () => {
10+
const breadcrumbItems = [
11+
"Products",
12+
"Categories",
13+
"Laptops",
14+
"Gaming Laptops",
15+
"XPS Pro"
16+
];
17+
18+
cy.mount(
19+
<Breadcrumbs>
20+
{breadcrumbItems.map((item, index) => (
21+
<BreadcrumbsItem key={index} href={`#${item}`}>{item}</BreadcrumbsItem>
22+
))}
23+
</Breadcrumbs>
24+
);
25+
26+
// Open the overflow popover by clicking on the dropdown arrow within shadow DOM
27+
cy.get("ui5-breadcrumbs")
28+
.shadow()
29+
.find(".ui5-breadcrumbs-dropdown-arrow-link-wrapper ui5-link")
30+
.click();
31+
32+
// Wait for the popover to be fully open
33+
cy.get("ui5-breadcrumbs")
34+
.shadow()
35+
.find("ui5-responsive-popover")
36+
.shadow()
37+
.find("ui5-dialog")
38+
.should("be.visible");
39+
40+
// Verify that all items are displayed in the popover
41+
cy.get("ui5-breadcrumbs")
42+
.shadow()
43+
.find("ui5-responsive-popover ui5-list ui5-li")
44+
.should("have.length", breadcrumbItems.length);
45+
46+
// Verify the items are in the correct order (reversed)
47+
cy.get("ui5-breadcrumbs")
48+
.shadow()
49+
.find("ui5-responsive-popover ui5-list ui5-li")
50+
.eq(0)
51+
.should("contain.text", breadcrumbItems[breadcrumbItems.length - 1]);
52+
});
53+
});

packages/main/src/Breadcrumbs.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,16 @@ class Breadcrumbs extends UI5Element {
554554
.reverse();
555555
}
556556

557+
/**
558+
* Returns all items that should be displayed in the popover on mobile devices
559+
* @private
560+
*/
561+
get _mobilePopoverItems() {
562+
return this._getItems()
563+
.filter(item => this._isItemVisible(item))
564+
.reverse();
565+
}
566+
557567
/**
558568
* Getter for the list of abstract breadcrumb items to be rendered as links outside the overflow
559569
*/

packages/main/src/BreadcrumbsPopoverTemplate.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import { isPhone } from "@ui5/webcomponents-base/dist/Device.js";
12
import type Breadcrumbs from "./Breadcrumbs.js";
23
import Button from "./Button.js";
34
import List from "./List.js";
45
import ListItemStandard from "./ListItemStandard.js";
56
import ResponsivePopover from "./ResponsivePopover.js";
67

78
export default function BreadcrumbsPopoverTemplate(this: Breadcrumbs) {
9+
const itemsToDisplay = isPhone()
10+
? this._mobilePopoverItems
11+
: this._overflowItemsData;
12+
813
return (
914
<ResponsivePopover
1015
class="ui5-breadcrumbs-popover"
@@ -21,7 +26,7 @@ export default function BreadcrumbsPopoverTemplate(this: Breadcrumbs) {
2126
separators="None"
2227
onSelectionChange={this._onOverflowListItemSelect}
2328
>
24-
{this._overflowItemsData.map(item =>
29+
{itemsToDisplay.map(item =>
2530
<ListItemStandard
2631
id={`${item._id}-li`}
2732
accessibleName={item.accessibleName}

0 commit comments

Comments
 (0)