feat: allow Menu.buildFromTemplate() to accept MenuItems (#16697)
* feat: allow Menu.buildFromTemplate to accept MenuItems * add another spec * fix linter error * add submenu spec
This commit is contained in:
parent
4211a9c69f
commit
858781ba83
3 changed files with 88 additions and 5 deletions
|
@ -168,7 +168,13 @@ Menu.buildFromTemplate = function (template) {
|
|||
const sorted = sortTemplate(filtered)
|
||||
|
||||
const menu = new Menu()
|
||||
sorted.forEach((item) => menu.append(new MenuItem(item)))
|
||||
sorted.forEach(item => {
|
||||
if (item instanceof MenuItem) {
|
||||
menu.append(item)
|
||||
} else {
|
||||
menu.append(new MenuItem(item))
|
||||
}
|
||||
})
|
||||
|
||||
return menu
|
||||
}
|
||||
|
@ -178,7 +184,11 @@ Menu.buildFromTemplate = function (template) {
|
|||
// validate the template against having the wrong attribute
|
||||
function areValidTemplateItems (template) {
|
||||
return template.every(item =>
|
||||
item != null && typeof item === 'object' && (item.hasOwnProperty('label') || item.hasOwnProperty('role') || item.type === 'separator'))
|
||||
item != null &&
|
||||
typeof item === 'object' &&
|
||||
(item.hasOwnProperty('label') ||
|
||||
item.hasOwnProperty('role') ||
|
||||
item.type === 'separator'))
|
||||
}
|
||||
|
||||
function sortTemplate (template) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue