Skip to content

Commit eb7cf4b

Browse files
fix(ui5-user-menu-item): scope uncheck prevention to showSelection only
Single-select unchecking is now only blocked when the parent item has showSelection set, so regular single-select groups remain uncheckable as expected.
1 parent ed06865 commit eb7cf4b

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,30 @@ describe("UserMenuItem", () => {
11261126
cy.get("[ui5-user-menu-item][text='Light']")
11271127
.should("have.attr", "checked");
11281128
});
1129+
1130+
it("allows unchecking in single-select mode when showSelection is false", () => {
1131+
cy.mount(
1132+
<>
1133+
<Button id="openUserMenuBtn">Open User Menu</Button>
1134+
<UserMenu open={true} opener="openUserMenuBtn">
1135+
<UserMenuItem text="Options">
1136+
<UserMenuItemGroup checkMode="Single">
1137+
<UserMenuItem text="Opt A" checked={true}></UserMenuItem>
1138+
<UserMenuItem text="Opt B"></UserMenuItem>
1139+
</UserMenuItemGroup>
1140+
</UserMenuItem>
1141+
</UserMenu>
1142+
</>
1143+
);
1144+
1145+
cy.get("[ui5-user-menu]").find("[ui5-user-menu-item][text='Options']").as("parentItem");
1146+
cy.get("@parentItem").click();
1147+
1148+
cy.get("[ui5-user-menu-item][text='Opt A']").click();
1149+
1150+
cy.get("[ui5-user-menu-item][text='Opt A']")
1151+
.should("not.have.attr", "checked");
1152+
});
11291153
});
11301154

11311155
describe("UserMenuItemGroup", () => {

packages/fiori/src/UserMenuItem.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@ class UserMenuItem extends MenuItem {
6161

6262
/**
6363
* Overrides the base MenuItem behavior to prevent unchecking
64-
* the currently checked item in single-select mode,
65-
* ensuring there is always a selection.
64+
* the currently checked item in single-select mode when
65+
* the parent item uses showSelection, ensuring there is always
66+
* a visible selection.
6667
*/
6768
_updateCheckedState() {
68-
if (this._checkMode === MenuItemGroupCheckMode.Single && this.checked) {
69+
const parentItem = this.parentElement?.parentElement;
70+
const hasShowSelection = parentItem instanceof UserMenuItem && parentItem.showSelection;
71+
72+
if (hasShowSelection && this._checkMode === MenuItemGroupCheckMode.Single && this.checked) {
6973
return;
7074
}
7175
super._updateCheckedState();

0 commit comments

Comments
 (0)