diff --git a/packages/fiori/cypress/specs/NavigationLayout.cy.ts b/packages/fiori/cypress/specs/NavigationLayout.cy.ts index 6ff02702aefa..c2310334d258 100644 --- a/packages/fiori/cypress/specs/NavigationLayout.cy.ts +++ b/packages/fiori/cypress/specs/NavigationLayout.cy.ts @@ -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); @@ -110,7 +110,7 @@ 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() @@ -118,7 +118,7 @@ describe("Navigation Layout on Phone", () => { .should("be.visible"); cy.get("[ui5-navigation-layout]") - .invoke("prop", "sideCollapsed", true); + .invoke("prop", "mode", "Collapsed"); cy.get("[ui5-navigation-layout]") .shadow() diff --git a/packages/fiori/src/NavigationLayout.ts b/packages/fiori/src/NavigationLayout.ts index 9fac78eb53d0..c6dd365543c7 100644 --- a/packages/fiori/src/NavigationLayout.ts +++ b/packages/fiori/src/NavigationLayout.ts @@ -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 @@ -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. * * ### ES6 Module Import * @@ -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. + * @default NavigationLayoutCollapsed.Auto + * @public + */ + @property() + mode: `${NavigationLayoutMode}` = "Auto"; + + /** + * @private + */ + @property({ type: Boolean }) + sideCollapsed : boolean = this._defaultSideCollapsed; /** * @private @@ -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. * @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; } /** @@ -114,6 +114,8 @@ class NavigationLayout extends UI5Element { content!: Array; onBeforeRendering() { + this.calcSideCollapsed(); + if (isPhone()) { return; } @@ -121,7 +123,15 @@ class NavigationLayout extends UI5Element { 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; } } } diff --git a/packages/fiori/src/types/NavigationLayoutMode.ts b/packages/fiori/src/types/NavigationLayoutMode.ts new file mode 100644 index 000000000000..1f5c8cb6e3c0 --- /dev/null +++ b/packages/fiori/src/types/NavigationLayoutMode.ts @@ -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 + * @public + */ + Collapsed = "Collapsed", + /** + * Expanded + * @public + */ + Expanded = "Expanded", +} + +export default NavigationLayoutMode; diff --git a/packages/fiori/test/pages/NavigationLayout.html b/packages/fiori/test/pages/NavigationLayout.html index 7d2ef53bf80d..a0e0c4eb3d35 100644 --- a/packages/fiori/test/pages/NavigationLayout.html +++ b/packages/fiori/test/pages/NavigationLayout.html @@ -161,7 +161,7 @@

Sub Item 2