From af2bc8c182ea4f61ca3797baa39a8e6c99950408 Mon Sep 17 00:00:00 2001 From: yajun Date: Thu, 8 Sep 2022 15:37:29 +0800 Subject: [PATCH] TASK #107657 OverflowMenu --- src/components/overflowmenu/overflowmenu.ts | 30 ++++++----- src/test/panels/overflowmenu/overflowmenu.ts | 56 ++++++-------------- 2 files changed, 34 insertions(+), 52 deletions(-) diff --git a/src/components/overflowmenu/overflowmenu.ts b/src/components/overflowmenu/overflowmenu.ts index ef3818b..3b3aa7a 100644 --- a/src/components/overflowmenu/overflowmenu.ts +++ b/src/components/overflowmenu/overflowmenu.ts @@ -35,40 +35,46 @@ export class StarOverflowMenu extends LitElement { const buttonbottom = Number(buttonposition?.bottom) const buttonleft = Number(buttonposition?.left) const buttonright = Number(buttonposition?.right) - const menuleft = (buttonright - buttonleft) / 2 + buttonleft // 通过“open”判断是否显示menu if (this.open == true) { for (var i = 0; i < this._evenEl.length; i++) { + const slotelement = this._evenEl[i] // 设置div显示display状态 mu.style.display = "block" // 设置显示位置类型 - this._evenEl[i].style.position = 'fixed' + // this._evenEl[i].style.position = 'fixed' + slotelement.style.position = 'relative' this.open = false // 获取溢出菜单width及height - const menuwidth = this._evenEl[i].getBoundingClientRect().width - const menuheight = this._evenEl[i].getBoundingClientRect().height + const menuwidth = slotelement.getBoundingClientRect().width + const menuheight = slotelement.getBoundingClientRect().height // 弹出菜单边界,rightline和bottomline分别为是否超过右侧和下侧显示区域 const rightline = (buttonright + menuwidth > bodywidth)?true:false const bottomline = (buttonbottom + menuheight > bodyheight)?true:false // 右下角边界 if (rightline && bottomline) { - this._evenEl[i].style.right = bodywidth - buttonright + 'px' - this._evenEl[i].style.top = buttontop - menuheight + 'px' + // this._evenEl[i].style.right = bodywidth - buttonright + 'px' + // this._evenEl[i].style.top = buttontop - menuheight + 'px' + // this._evenEl[i].style.right = menuwidth + (bodywidth - buttonright) - (buttonright - buttonleft) + 'px' + slotelement.style.left = -(menuwidth - (buttonright - buttonleft)) + 'px' + slotelement.style.bottom = menuheight + (buttonbottom - buttontop) + 'px' return } else if (rightline) { // 右侧边界 - this._evenEl[i].style.right = bodywidth - buttonright + 'px' - this._evenEl[i].style.top = buttonbottom + 'px' + // this._evenEl[i].style.right = bodywidth - buttonright + 'px' + // this._evenEl[i].style.top = buttonbottom + 'px' + slotelement.style.right = menuwidth - (buttonright - buttonleft) + 'px' return } else if (bottomline) { // 下侧边界 - this._evenEl[i].style.top = buttontop - menuheight + 'px' - this._evenEl[i].style.left = menuleft + 'px' + // this._evenEl[i].style.top = buttontop - menuheight + 'px' + // this._evenEl[i].style.left = menuleft + 'px' + slotelement.style.bottom = menuheight + (buttonbottom - buttontop) + 'px' return } else { // 正常情况 - this._evenEl[i].style.left = menuleft + 'px' - this._evenEl[i].style.top = buttonbottom + 'px' + // this._evenEl[i].style.left = menuleft + 'px' + // this._evenEl[i].style.top = buttonbottom + 'px' return } } diff --git a/src/test/panels/overflowmenu/overflowmenu.ts b/src/test/panels/overflowmenu/overflowmenu.ts index 17b1c73..c0a2778 100644 --- a/src/test/panels/overflowmenu/overflowmenu.ts +++ b/src/test/panels/overflowmenu/overflowmenu.ts @@ -25,6 +25,7 @@ export class PanelOverflowMenu extends LitElement { } // 如果点在空白处则关闭菜单 if (tagName != 'star-overflowmenu') { + // 获取所有的star-overflowmenu var menulist = this.shadowRoot!.querySelectorAll('star-overflowmenu') for (var i = 0; i < menulist.length; i++) { menulist[i].open = true @@ -58,40 +59,11 @@ export class PanelOverflowMenu extends LitElement { return html`
- - + - - - - - - - - @@ -131,12 +103,12 @@ export class PanelOverflowMenu extends LitElement { icon="more" style="position: fixed; bottom: 0; left: 0;" > - - + + @@ -157,7 +129,11 @@ export class PanelOverflowMenu extends LitElement { } static styles = css` - :host, + :host { + display: block; + width: 100vw; + height: 100vh; + } div { display: block; width: 100vw;