Skip to content

Commit

Permalink
fix: 二级菜单定位错误 close #514
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsonliu committed Jul 28, 2023
1 parent 8a26cda commit a437562
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/toolbars/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,16 @@ export default class Toolbar {
this.options.dom.appendChild(toolbarRight);
}

setSubMenuPosition(menuObj, subMenuObj) {
const pos = menuObj.getMenuPosition();
subMenuObj.style.left = `${pos.left + pos.width / 2}px`;
subMenuObj.style.top = `${pos.top + pos.height}px`;
subMenuObj.style.position = menuObj.positionModel;
}

drawSubMenus(name) {
const menu = this.menus.hooks[name];
const pos = menu.getMenuPosition();
this.subMenus[name] = createElement('div', 'cherry-dropdown', { name });
this.subMenus[name].style.left = `${pos.left + pos.width / 2}px`;
this.subMenus[name].style.top = `${pos.top + pos.height}px`;
this.subMenus[name].style.position = menu.positionModel;
this.setSubMenuPosition(this.menus.hooks[name], this.subMenus[name]);
// 如果有配置的二级菜单
const level2MenusName = this.isHasLevel2Menu(name);
if (level2MenusName) {
Expand Down Expand Up @@ -207,6 +210,7 @@ export default class Toolbar {
// 如果是隐藏的,则先隐藏所有二级菜单,再显示当前二级菜单
this.hideAllSubMenu();
this.subMenus[name].style.display = 'block';
this.setSubMenuPosition(this.menus.hooks[name], this.subMenus[name]);
} else {
// 如果是显示的,则隐藏当前二级菜单
this.subMenus[name].style.display = 'none';
Expand Down

0 comments on commit a437562

Please sign in to comment.