Skip to content

Commit b5c4a92

Browse files
authored
feat(ui5-side-navigation): add "header" slot (#2520)
Provide API, header slot, displayed in the top-most area of the SideNavigation component to enable users adding additional information, usually profile/user data, avatar, etc. Also includes a minor fix (min-width: 3rem;) that prevents the SideNavigation (when collapsed) from shrinking due to resize. FIXES #2518
1 parent d7542af commit b5c4a92

File tree

5 files changed

+77
-7
lines changed

5 files changed

+77
-7
lines changed

packages/fiori/src/SideNavigation.hbs

+7-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<div class="ui5-sn-spacer"></div>
3838

3939
{{#if fixedItems.length}}
40-
<div>
40+
<div>
4141
<div class="ui5-sn-bottom-content-border">
4242
<span></span>
4343
</div>
@@ -70,12 +70,16 @@
7070
</ui5-tree-item>
7171
{{/each}}
7272
</ui5-tree>
73-
</div>
73+
</div>
7474
{{/if}}
7575

7676
{{> footer }}
7777
</div>
7878

79-
{{#*inline header}}{{/inline}}
79+
{{#*inline header}}
80+
{{#if showHeader}}
81+
<slot name="header"></slot>
82+
{{/if}}
83+
{{/inline}}
8084

8185
{{#*inline footer}}{{/inline}}

packages/fiori/src/SideNavigation.js

+29-4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ const metadata = {
5151
type: HTMLElement,
5252
},
5353

54+
/**
55+
* Defines the header of the <code>ui5-side-navigation</code>.
56+
*
57+
* <br><br>
58+
* <b>Note:</b> The header is displayed when the component is expanded - the property <code>collapsed</code> is false;
59+
*
60+
* @public
61+
* @since 1.0.0-rc.11
62+
* @slot
63+
*/
64+
header: {
65+
type: HTMLElement,
66+
},
67+
5468
/**
5569
* Defines the fixed items at the bottom of the <code>ui5-side-navigation</code>. Use the <code>ui5-side-navigation-item</code> component
5670
* for the fixed items, and optionally the <code>ui5-side-navigation-sub-item</code> component to provide second-level items inside them.
@@ -87,10 +101,13 @@ const metadata = {
87101
* <h3 class="comment-api-title">Overview</h3>
88102
*
89103
* The <code>SideNavigation</code> is used as a standard menu in applications.
90-
* It consists of two containers: the main navigation section (top-aligned) and the secondary section (bottom-aligned).
91-
* Usually the main navigation section is related to the user’s current work context,
92-
* whereas the secondary section is mostly used to link additional information that may be of interest (legal information, developer communities, external help, contact information and so on).
93-
104+
* It consists of three containers: header (top-aligned), main navigation section (top-aligned) and the secondary section (bottom-aligned).
105+
* <ul>
106+
* <li>The header is meant for displaying user related information - profile data, avatar, etc.</li>
107+
* <li>The main navigation section is related to the user’s current work context</li>
108+
* <li>The secondary section is mostly used to link additional information that may be of interest (legal information, developer communities, external help, contact information and so on). </li>
109+
* </ul>
110+
*
94111
* <h3>Usage</h3>
95112
*
96113
* Use the available <code>ui5-side-navigation-item</code> and <code>ui5-side-navigation-sub-item</code> components to build your menu.
@@ -227,6 +244,14 @@ class SideNavigation extends UI5Element {
227244
responsivePopover.close();
228245
}
229246

247+
get hasHeader() {
248+
return !!this.header.length;
249+
}
250+
251+
get showHeader() {
252+
return this.hasHeader && !this.collapsed;
253+
}
254+
230255
get _itemsTree() {
231256
return this.getDomRef().querySelector("#ui5-sn-items-tree");
232257
}

packages/fiori/src/themes/SideNavigation.css

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
:host([collapsed]) {
1111
width: 3rem;
12+
min-width: 3rem;
1213
}
1314

1415
.ui5-sn-bottom-content-border {

packages/fiori/test/pages/SideNavigation.html

+18
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
ui5-shellbar::part(root) {
4040
padding-left: .5rem;
4141
}
42+
43+
.header {
44+
display: flex;
45+
flex-direction: column;
46+
padding: 1rem;
47+
box-sizing: border-box;
48+
}
4249
</style>
4350
</head>
4451

@@ -53,6 +60,16 @@
5360

5461
<div class="content">
5562
<ui5-side-navigation id="sn1">
63+
64+
<!-- Header -->
65+
<div slot="header" class="header">
66+
<ui5-avatar size="L" image="./img/man_avatar_1.png"></ui5-avatar>
67+
<br>
68+
<ui5-title>Willam Brown</ui5-title>
69+
<ui5-label>UX expert</ui5-label>
70+
</div>
71+
72+
<!-- Items -->
5673
<ui5-side-navigation-item text="Home" icon="home" ></ui5-side-navigation-item>
5774
<ui5-side-navigation-item text="People" expanded icon="group">
5875
<ui5-side-navigation-sub-item text="From My Team" icon="employee-approvals"></ui5-side-navigation-sub-item>
@@ -64,6 +81,7 @@
6481
<ui5-side-navigation-sub-item text="Others"></ui5-side-navigation-sub-item>
6582
</ui5-side-navigation-item>
6683

84+
<!-- Fixed Items -->
6785
<ui5-side-navigation-item slot="fixedItems" text="Usefull Links" icon="chain-link">
6886
<ui5-side-navigation-sub-item text="Vacation Tool"></ui5-side-navigation-sub-item>
6987
<ui5-side-navigation-sub-item text="HR tool"></ui5-side-navigation-sub-item>

packages/fiori/test/specs/SideNavigation.spec.js

+22
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,27 @@ describe("Component Behavior", () => {
5959
assert.strictEqual(input.getProperty("value"), "6", "Event is not fired");
6060
assert.strictEqual(items[3].getAttribute("expanded"), "false", "Expanded is toggled");
6161
});
62+
63+
it("Tests header visibility", () => {
64+
let showHeader = null;
65+
66+
showHeader = browser.execute(() => {
67+
const sideNavigation = document.querySelector("#sn1");
68+
sideNavigation.collapsed = false;
69+
70+
return sideNavigation.showHeader;
71+
});
72+
73+
assert.strictEqual(showHeader, true, "Header is displayed");
74+
75+
showHeader = browser.execute( () => {
76+
const sideNavigation = document.querySelector("#sn1");
77+
sideNavigation.collapsed = true;
78+
79+
return sideNavigation.showHeader;
80+
});
81+
82+
assert.strictEqual(showHeader, false, "Header is not displayed");
83+
});
6284
});
6385
});

0 commit comments

Comments
 (0)