Skip to content

feat(ui5-menu): menu item groups with checkable menu items #10028

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

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

NHristov-sap
Copy link
Contributor

@NHristov-sap NHristov-sap commented Oct 15, 2024

This PR introduces MenuItemGroup component that can hold regular MenuItem components. The MenuItemGroup has a property named itemCheckMode which can have values among None (default), Single and Multiple. MenuItemGroup can be slotted in a Menu or MenuItem default slot as any other regular MenuItem. Nesting of MenuItemGroup components is not allowed, but any Menu or MenuItem can contain more than one MenuItemGroup components with different itemCheckMode settings.

When itemCheckMode is:

  • None, the Menu acts exactly like until now.
  • Single means that zero or one MenuItems can be checked at a time.
  • Multiple means that zero or many MenuItems can be checked at a time.

There is also new property checked introduced in MenuItem. By setting it the item is marked as checked and this is visualized as checkmark at the end of the item. This property is taken into account only when the corresponding item is a member of MenuItemGroup with Single or Multiple value of itemCheckMode.

image

It is recommended to place separators before and after each MenuItemGroup, but this is not mandatory and depends on the application developers.

@NHristov-sap NHristov-sap requested a review from hinzzx October 18, 2024 12:17
Copy link
Contributor

@nnaydenow nnaydenow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking unti: #10070

@nnaydenow nnaydenow dismissed their stale review October 22, 2024 13:52

Menu tests are fixed and this PR no longer need to be blocked

@NHristov-sap NHristov-sap reopened this May 2, 2025
@github-actions github-actions bot removed the Stale label May 3, 2025

const newState = !this.checked;

this.fireDecoratorEvent("item-check");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event should be fired after the state has been updated. When the event is triggered, its target must reflect the component’s current state (i.e., checked).

Note: If this event becomes cancelable in the future, a revert mechanism will need to be implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already obsolete as the event is made private now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree with Nayden that the only valid reason for firing the event before changing the value is if you want the event to be preventable. And furthermore if you fire the event before changing the value you should provide the new value.

@NHristov-sap NHristov-sap changed the title feat(ui5-menu): selectable menu items feat(ui5-menu): menu item groups with checkable menu items May 12, 2025
@github-actions github-actions bot added the Stale label Jun 5, 2025
@@ -0,0 +1,134 @@
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
Copy link
Member

@ilhan007 ilhan007 Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General remark:

As there is no public event as far I can see from the change, the apps won't be able to handle changes in the checked state of menu items inside menu groups and update their models on interaction. Or, are there other means addressing this?

I think we need to provide a public event in the MenuItemGroup - something like selection-change. But as we use checked in this case, so it should be item-check or check-change. The second is more consistent, but sounds odd - it's for the KM's to review it as well.

No matter the name, it will be good if the event provide some details to get the checked items from the event - e.detail.checkedItems, f.e:

type MenuItemGroupItemCheckEventDetail = {
	checkedItems: Array<IMenuItem>;
}

*If you like item-check, you need to rename the private event of the MenuItem from item-check to check or _item-check or something else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My opinion is that additional event is not needed - now we have item-click event. The check/uncheck happens on click of the item, so this event can notify for check state changes. The clicked item is provided in the event detail. The developer can check item's checked property and can update the model.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unresolved by your previous comment above where you said that the item-check event is now private.

@github-actions github-actions bot removed the Stale label Jun 11, 2025
}

return super.focus(focusOptions);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method was moved without any modifications. In the context of such a large change, this creates unnecessary clutter in the diff.

return true;
}

get isRtl() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same as above. No need for moving the method

return items;
}

onBeforeRendering() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method was moved without any changes. As a general recommendation, I suggest avoiding moving methods at all—especially in large changes—since it adds unnecessary noise to the diff and makes the review harder to follow. I won't comment on each moved method individually, but this feedback applies to all such cases.

You can always re-order the methods with later change. Although I also do not recommend this because it makes following the history harder.

* the last checked item will take precedence.
* @private
*/
_ensureSingleItemIsChecked() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MAJOR] To be checked with core team: The overall design of this method is flawed. It modifies the checked property of all items directly without notifying the application, which can cause the UI to fall out of sync—especially in a React environment where state synchronization is critical.


const newState = !this.checked;

this.fireDecoratorEvent("item-check");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree with Nayden that the only valid reason for firing the event before changing the value is if you want the event to be preventable. And furthermore if you fire the event before changing the value you should provide the new value.

@@ -0,0 +1,134 @@
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unresolved by your previous comment above where you said that the item-check event is now private.

const siblingsWithIcon = this._menuItems.some(menuItem => !!menuItem.icon);
const siblingsWithIcon = this._allMenuItems.some(menuItem => !!menuItem.icon);

this._setupItemNavigation();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed for checked state feature? If not better separate in a new change. And all related code to item navigation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants