Hello,
I deactivated the focusOnHover property for the TaskMenu but I found no way to deactivate it for the submenu "Add". How can this be achieved?
Greetings
The goal of not automatically focusing is the possibility to have different stylings for hover and focus.
And that's not possible if hover and focus are basically the same.
For the top level, focusOnHover = false is working but not for submenus.
This is what I currently have:
{
menu: {
focusOnHover: false,
},
items: {
add: {
menu: {
subMenuItem1: {},
subMenuItem2: {}
}
}
}
}
Reproduced. We'll investigate it. Here is the ticket to track progress https://github.com/bryntum/support/issues/9757
Best regards,
Tasnim
It's because it's using the menu
as the items
. Try this:
{
menu: {
focusOnHover: false,
},
items : {
add: {
menu: {
focusOnHover: false,
items : {
subMenuItem1: {},
subMenuItem2: {}
}
}
}
}
}
menu : { <the submenu items> }
is a shortcut if all you are doing is adding a menu. But if you want to configure that menu in addition to specifying items, you have to separate them.
It can't tell which properties are intended to be child items and which are to be configuration properties for the menu. So there has to be a items
property.
The code below propagates the focusOnHover
setting from any top level menu to all submenus, making the UX at least consistent if not standard:
The ticket solution will propagate that setting.
This is the incantation in that example:
MenuItem.prototype.changeMenu = function(config, existingMenu) {
const
me = this,
{ owner } = me,
{ constrainTo, scrollAction, focusOnHover } = owner,
defaults = {
owner : me,
defaults : {
type : 'menu',
align : 's0-e0',
anchor : true,
autoClose : true,
autoShow : false,
cls : {
'b-sub-menu' : 1 // Marks the widget as a submenu
},
forElement : me.element,
owner : me,
ariaLabel : me.text,
constrainTo,
scrollAction
}
};
// This covers both Array and Object which are valid items config formats.
// menu could be { itemRef : { text : 'sub item 1 } }. But if it has
// child items or html property in it, it's the main config
if (config && typeof config === 'object' && !('items' in config) && !('widgets' in config) && !('html' in config)) {
config = {
lazyItems : config
};
}
// Propagate the focusOnHover setting to all submenus in the hierarchy
if (owner.isMenu) {
me.closeParent = focusOnHover;
defaults.focusOnHover = focusOnHover;
}
return Menu.reconfigure(existingMenu, config, defaults);
}
Obviously the Menu
and MenuItem
classes must be imported
to do this.