feat: add menu item role palette and header (#45538)

* feat: add menu item role `palette` and `header`

* adds comments

* refactors new role items to new item types

* docs: custom type

* docs: note types only available on mac 14+

---------

Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>
This commit is contained in:
Gellert Hegyi 2025-05-23 18:43:49 +02:00 committed by GitHub
commit b9b96a96f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 61 additions and 8 deletions

View file

@ -71,7 +71,7 @@ const MenuItem = function (this: any, options: any) {
};
};
MenuItem.types = ['normal', 'separator', 'submenu', 'checkbox', 'radio'];
MenuItem.types = ['normal', 'separator', 'submenu', 'checkbox', 'radio', 'header', 'palette'];
MenuItem.prototype.getDefaultRoleAccelerator = function () {
return roles.getDefaultAccelerator(this.role);

View file

@ -143,6 +143,9 @@ Menu.prototype.insert = function (pos, item) {
if (item.toolTip) this.setToolTip(pos, item.toolTip);
if (item.icon) this.setIcon(pos, item.icon);
if (item.role) this.setRole(pos, item.role);
if (item.type === 'palette' || item.type === 'header') {
this.setCustomType(pos, item.type);
}
// Make menu accessible to items.
item.overrideReadOnlyProperty('menu', this);
@ -264,9 +267,11 @@ function removeExtraSeparators (items: (MenuItemConstructorOptions | MenuItem)[]
function insertItemByType (this: MenuType, item: MenuItem, pos: number) {
const types = {
normal: () => this.insertItem(pos, item.commandId, item.label),
header: () => this.insertItem(pos, item.commandId, item.label),
checkbox: () => this.insertCheckItem(pos, item.commandId, item.label),
separator: () => this.insertSeparator(pos),
submenu: () => this.insertSubMenu(pos, item.commandId, item.label, item.submenu),
palette: () => this.insertSubMenu(pos, item.commandId, item.label, item.submenu),
radio: () => {
// Grouping radio menu items
item.overrideReadOnlyProperty('groupId', generateGroupId(this.items, pos));