Skip to content

Commit 8ec71e3

Browse files
authored
fix(ui5-side-navigation): disabled groups no longer interactive (#11404)
fixes: #11384
1 parent 850fa42 commit 8ec71e3

File tree

3 files changed

+72
-5
lines changed

3 files changed

+72
-5
lines changed

packages/fiori/cypress/specs/SideNavigationWithGroups.cy.tsx

+42-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import SideNavigationGroup from "../../src/SideNavigationGroup.js";
33
import SideNavigationItem from "../../src/SideNavigationItem.js";
44

55
describe("Component Behavior", () => {
6-
describe("Main functionality", async () => {
7-
it("rendering", async () => {
6+
describe("Main functionality", () => {
7+
it("rendering", () => {
88
cy.mount(
99
<SideNavigation style="height: 90vh; " id="sn1" collapsed={false}>
10+
<SideNavigationItem text="Item" />
1011
<SideNavigationGroup id="group1" expanded text="Group">
1112
<SideNavigationItem text="Home 1"
1213
icon="home"
@@ -28,15 +29,23 @@ describe("Component Behavior", () => {
2829
.should("not.exist");
2930
});
3031

31-
it("collapse/expand", async () => {
32+
it("collapse/expand", () => {
3233
cy.mount(
3334
<SideNavigation style="height: 90vh; " id="sn1">
35+
<SideNavigationItem text="Item" />
3436
<SideNavigationGroup id="group1" expanded text="Group">
3537
<SideNavigationItem text="Home 1"
3638
icon="home"
3739
href="#home"
3840
title="Home tooltip" />
3941
</SideNavigationGroup>
42+
<SideNavigationItem text="Item" />
43+
<SideNavigationGroup id="group2" disabled text="Group">
44+
<SideNavigationItem text="Home 2"
45+
icon="home"
46+
href="#home"
47+
title="Home tooltip" />
48+
</SideNavigationGroup>
4049
</SideNavigation>);
4150

4251
cy.get("#group1").should("have.prop", "expanded", true);
@@ -45,13 +54,42 @@ describe("Component Behavior", () => {
4554
.shadow()
4655
.find(".ui5-sn-item")
4756
.realClick();
48-
cy.get("#group1").should("not.have.prop", "expanded");
57+
cy.get("#group1").should("have.prop", "expanded", false);
4958

5059
cy.get("#group1")
5160
.shadow()
5261
.find(".ui5-sn-item")
5362
.realClick();
5463
cy.get("#group1").should("have.prop", "expanded", true);
64+
65+
cy.get("#group2")
66+
.shadow()
67+
.find(".ui5-sn-item")
68+
.realClick();
69+
cy.get("#group2").should("have.prop", "expanded", false);
70+
});
71+
72+
it("disabled", () => {
73+
cy.mount(
74+
<SideNavigation style="height: 90vh; " id="sn1">
75+
<SideNavigationItem text="Item" />
76+
<SideNavigationGroup id="group1" expanded text="Group 1">
77+
<SideNavigationItem text="Home 1" />
78+
<SideNavigationItem disabled text="Home 1" />
79+
</SideNavigationGroup>
80+
</SideNavigation>);
81+
82+
cy.get("#group1").should("not.have.attr", "disabled");
83+
cy.get("#group1").invoke("prop", "disabled", true);
84+
cy.get("#group1").should("have.attr", "disabled");
85+
86+
cy.get("#group1").then(($group) => {
87+
const group = $group[0] as SideNavigationGroup;
88+
cy.wrap(group.items).each((item: SideNavigationItem) => {
89+
cy.wrap(item).should("have.prop", "disabled", true);
90+
});
91+
});
5592
});
93+
5694
});
5795
});

packages/fiori/src/SideNavigationGroup.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ class SideNavigationGroup extends SideNavigationItemBase {
6868
@i18n("@ui5/webcomponents-fiori")
6969
static i18nBundle: I18nBundle;
7070

71+
_initialChildDisabledStates: Map<SideNavigationItemBase, boolean> = new Map();
72+
73+
onBeforeRendering() {
74+
this.allItems.forEach(item => {
75+
if (!this._initialChildDisabledStates.has(item)) {
76+
this._initialChildDisabledStates.set(item, item.disabled);
77+
}
78+
});
79+
80+
this._updateChildItemsDisabledState();
81+
}
82+
83+
_updateChildItemsDisabledState() {
84+
this.allItems.forEach(item => {
85+
if (this.disabled) {
86+
item.disabled = true;
87+
} else {
88+
item.disabled = this._initialChildDisabledStates.get(item)!;
89+
}
90+
});
91+
}
92+
7193
get overflowItems() : Array<HTMLElement> {
7294
const separator1 = this.shadowRoot!.querySelector<HTMLElement>(".ui5-sn-item-separator:first-child")!;
7395
const separator2 = this.shadowRoot!.querySelector<HTMLElement>(".ui5-sn-item-separator:last-child")!;
@@ -156,7 +178,9 @@ class SideNavigationGroup extends SideNavigationItemBase {
156178
}
157179

158180
_toggle() {
159-
this.expanded = !this.expanded;
181+
if (!this.disabled) {
182+
this.expanded = !this.expanded;
183+
}
160184
}
161185

162186
get isSideNavigationGroup() {

packages/fiori/test/pages/SideNavigationWithGroups.html

+5
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104

105105
<div style="float: right">
106106
<ui5-checkbox id="collapsed" text="Collapsed"></ui5-checkbox>
107+
<ui5-checkbox id="disable" text="disable group 1"></ui5-checkbox>
107108
<ui5-checkbox id="density" text="Compact density"></ui5-checkbox>
108109
<br>
109110
<ui5-label for="slider" show-colon>Change width</ui5-label>
@@ -124,6 +125,10 @@
124125
document.body.classList.toggle("ui5-content-density-compact", e.target.checked);
125126
});
126127

128+
document.getElementById("disable").addEventListener("change", e => {
129+
document.getElementById("group1").toggleAttribute("disabled", e.target.checked);
130+
});
131+
127132
slider.addEventListener("ui5-input", function (event) {
128133
sn1.style.width = event.target.value + 'px';
129134
});

0 commit comments

Comments
 (0)