Skip to content
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

fix(ui5-navigation-layout): replace "sideCollapsed" property with "mode" property #10390

Merged
merged 24 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8a9825c
fix(ui5-navigation-layout): change side-collapsed property
TeodorTaushanov Dec 13, 2024
96291cc
Merge remote-tracking branch 'origin/main' into navigation_layout_col…
TeodorTaushanov Dec 13, 2024
c50ee4a
Merge remote-tracking branch 'origin/main' into navigation_layout_col…
TeodorTaushanov Dec 13, 2024
ee5cc4b
chore: add private actualSideCollapsed
TeodorTaushanov Dec 13, 2024
9a795a7
Merge remote-tracking branch 'origin/main' into navigation_layout_col…
TeodorTaushanov Dec 16, 2024
bae7110
chore: use "effective" word
TeodorTaushanov Dec 16, 2024
1179afb
Merge remote-tracking branch 'origin/main' into navigation_layout_col…
TeodorTaushanov Dec 16, 2024
ddaf4a9
chore: fix lint error
TeodorTaushanov Dec 16, 2024
4d24a77
chore: fix lint error and docs
TeodorTaushanov Dec 16, 2024
30d2560
Merge remote-tracking branch 'origin/main' into navigation_layout_col…
TeodorTaushanov Dec 17, 2024
b351294
chore: rename the property and the enum
TeodorTaushanov Dec 17, 2024
2bcc158
chore: fix css
TeodorTaushanov Dec 17, 2024
c61e57a
chore: remove custom setter
TeodorTaushanov Dec 17, 2024
ecf744f
chore: fix docs
TeodorTaushanov Dec 17, 2024
b731654
Merge remote-tracking branch 'origin/main' into navigation_layout_col…
TeodorTaushanov Dec 17, 2024
0842c70
chore: fix docs
TeodorTaushanov Dec 17, 2024
bb87ca0
Merge remote-tracking branch 'origin/main' into navigation_layout_col…
TeodorTaushanov Dec 20, 2024
9a80680
chore: adress code comments
TeodorTaushanov Dec 20, 2024
f0964f8
Merge remote-tracking branch 'origin/main' into navigation_layout_col…
TeodorTaushanov Dec 20, 2024
abb1b76
chore: fix test
TeodorTaushanov Dec 20, 2024
ec85004
Merge remote-tracking branch 'origin/main' into navigation_layout_col…
TeodorTaushanov Jan 6, 2025
658a67a
chore: address code comments
TeodorTaushanov Jan 6, 2025
640f157
chore: fix jsdoc
TeodorTaushanov Jan 6, 2025
70dde21
chore: address code comments
TeodorTaushanov Jan 6, 2025
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
8 changes: 4 additions & 4 deletions packages/fiori/cypress/specs/NavigationLayout.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ describe("Rendering and interaction", () => {
.should("have.prop", "collapsed", false);

cy.get("[ui5-navigation-layout]")
.invoke("prop", "sideCollapsed", true);
.invoke("prop", "mode", "Collapsed");

cy.get("[ui5-side-navigation]")
.should("have.prop", "collapsed", true);

cy.get("[ui5-navigation-layout]")
.invoke("prop", "sideCollapsed", false);
.invoke("prop", "mode", "Expanded");

cy.get("[ui5-side-navigation]")
.should("have.prop", "collapsed", false);
Expand Down Expand Up @@ -110,15 +110,15 @@ describe("Navigation Layout on Phone", () => {

it("tests collapsing", () => {
cy.get("[ui5-navigation-layout]")
.invoke("prop", "sideCollapsed", false);
.invoke("prop", "mode", "Expanded");

cy.get("[ui5-navigation-layout]")
.shadow()
.find(".ui5-nl-aside")
.should("be.visible");

cy.get("[ui5-navigation-layout]")
.invoke("prop", "sideCollapsed", true);
.invoke("prop", "mode", "Collapsed");

cy.get("[ui5-navigation-layout]")
.shadow()
Expand Down
58 changes: 34 additions & 24 deletions packages/fiori/src/NavigationLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
isTablet,
isCombi,
} from "@ui5/webcomponents-base/dist/Device.js";
import NavigationLayoutMode from "./types/NavigationLayoutMode.js";
import type SideNavigation from "./SideNavigation.js";

// Template
Expand All @@ -31,9 +32,10 @@ import NavigationLayoutCss from "./generated/themes/NavigationLayout.css.js";
*
* ### Responsive Behavior
*
* On desktop and tablet devices, the side navigation remains visible and can
* be expanded or collapsed using the `sideCollapsed` property. On phone devices, the side navigation
* is hidden by default but can be displayed using the same `sideCollapsed` property.
* On desktop and tablet devices, the side navigation is visible
* by default and can be expanded or collapsed using the `mode` property.
* On phone devices, the side navigation is hidden by default and can
* be displayed using the `mode` property.
*
TeodorTaushanov marked this conversation as resolved.
Show resolved Hide resolved
* ### ES6 Module Import
*
Expand All @@ -54,7 +56,21 @@ import NavigationLayoutCss from "./generated/themes/NavigationLayout.css.js";
template: NavigationLayoutTemplate,
})
class NavigationLayout extends UI5Element {
_sideCollapsed = isPhone() || (isTablet() && !isCombi());
_defaultSideCollapsed = isPhone() || (isTablet() && !isCombi());

/**
* Specifies the navigation mode.
TeodorTaushanov marked this conversation as resolved.
Show resolved Hide resolved
* @default NavigationLayoutCollapsed.Auto
* @public
*/
@property()
mode: `${NavigationLayoutMode}` = "Auto";

/**
* @private
*/
@property({ type: Boolean })
sideCollapsed : boolean = this._defaultSideCollapsed;

/**
* @private
Expand All @@ -69,27 +85,11 @@ class NavigationLayout extends UI5Element {
isTablet = isTablet() && !isCombi();

/**
* Indicates whether the side navigation is collapsed.
* @default false
* Gets whether the side navigation is collapsed.
TeodorTaushanov marked this conversation as resolved.
Show resolved Hide resolved
* @public
*/
@property({ type: Boolean })
set sideCollapsed(value: boolean) {
this._sideCollapsed = value;

if (isPhone()) {
return;
}

const sideNavigation = this.sideContent[0];

if (sideNavigation) {
sideNavigation.collapsed = value;
}
}

get sideCollapsed() : boolean {
return this._sideCollapsed;
isSideCollapsed() : boolean {
return this.sideCollapsed;
}

/**
Expand All @@ -114,14 +114,24 @@ class NavigationLayout extends UI5Element {
content!: Array<HTMLElement>;

onBeforeRendering() {
this.calcSideCollapsed();

if (isPhone()) {
return;
}

const sideNavigation = this.sideContent[0];

if (sideNavigation) {
sideNavigation.collapsed = this.sideCollapsed;
sideNavigation.collapsed = this.isSideCollapsed();
}
}

calcSideCollapsed() {
if (this.mode === NavigationLayoutMode.Auto) {
this.sideCollapsed = this._defaultSideCollapsed;
} else {
this.sideCollapsed = this.mode === NavigationLayoutMode.Collapsed;
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions packages/fiori/src/types/NavigationLayoutMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Specifies the navigation layout mode.
* @public
*/
enum NavigationLayoutMode {
/**
* Automatically calculates the collapsed mode based on the screen device type.
* `Expanded` on desktop and `Collapsed` on tablet and phone.
* @public
*/
Auto = "Auto",
/**
* Collapsed
TeodorTaushanov marked this conversation as resolved.
Show resolved Hide resolved
* @public
*/
Collapsed = "Collapsed",
/**
* Expanded
* @public
*/
Expanded = "Expanded",
TeodorTaushanov marked this conversation as resolved.
Show resolved Hide resolved
}

export default NavigationLayoutMode;
4 changes: 2 additions & 2 deletions packages/fiori/test/pages/NavigationLayout.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ <h2>Sub Item 2</h2>

<script>
document.querySelector("#startButton").addEventListener("click", function (event) {
nl1.sideCollapsed = !nl1.sideCollapsed;
nl1.mode = nl1.isSideCollapsed() ? "Expanded" : "Collapsed";
});

document.querySelector("#sn1").addEventListener("selection-change", function (event) {
Expand All @@ -171,7 +171,7 @@ <h2>Sub Item 2</h2>

const contentItems = document.querySelectorAll(".contentItem"),
divId = "cont" + event.detail.item.getAttribute("href").replace("#", "").charAt(0).toUpperCase() + event.detail.item.getAttribute("href").replace("#", "").slice(1);

contentItems.forEach(item => {
item.classList.remove("contentItemVisible");
});
Expand Down
4 changes: 2 additions & 2 deletions packages/fiori/test/pages/NavigationLayoutSubHeader.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<ui5-tab slot="items" text="Child Tab Text"></ui5-tab>
<ui5-tab slot="items" text="Child Tab Text"></ui5-tab>
</ui5-tab>

</ui5-tabcontainer>
</div>
<div class="content">
Expand Down Expand Up @@ -142,7 +142,7 @@ <h2>Sub Item 2</h2>

<script>
document.querySelector("#startButton").addEventListener("click", function (event) {
nl1.sideCollapsed = !nl1.sideCollapsed;
nl1.mode = nl1.isSideCollapsed() ? "Expanded" : "Collapsed";
});

document.querySelector("#sn1").addEventListener("selection-change", function (event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import "@ui5/webcomponents-icons/dist/compare.js";
import "@ui5/webcomponents-icons/dist/locked.js";

document.querySelector("#startButton").addEventListener("click", function (event) {
nl1.sideCollapsed = !nl1.sideCollapsed;
nl1.mode = nl1.isSideCollapsed() ? "Expanded" : "Collapsed";
TeodorTaushanov marked this conversation as resolved.
Show resolved Hide resolved
});

document.querySelector("#sn1").addEventListener("selection-change", function (event) {
Expand Down
Loading