Skip to content

Commit

Permalink
fix: btn list
Browse files Browse the repository at this point in the history
  • Loading branch information
Xmader committed Dec 1, 2020
1 parent b6837ee commit 2a29e37
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/btn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,29 @@ export class BtnList {
const btnParent = document.querySelector('div') as HTMLDivElement
const shadow = attachShadow(btnParent)

try {
const anchorDiv = this.getBtnParent()
const { width, top, left } = anchorDiv.getBoundingClientRect()
btnParent.style.width = `${width}px`
btnParent.style.top = `${top}px`
btnParent.style.left = `${left}px`
} catch (err) {
console.error(err)
}

// style the shadow DOM
const style = document.createElement('style')
style.innerText = btnListCss
shadow.append(style)

// hide buttons using the shadow DOM
const newParent = btnParent.cloneNode(false) as HTMLDivElement
newParent.append(...this.list.map(e => cloneBtn(e)))
shadow.append(newParent)
const slot = document.createElement('slot')
shadow.append(slot)

const newParent = document.createElement('div')
newParent.append(...this.list.map(e => cloneBtn(e)))
shadow.append(newParent)

try {
const anchorDiv = this.getBtnParent()
const { width, top, left } = anchorDiv.getBoundingClientRect()
newParent.style.width = `${width}px`
newParent.style.top = `${top}px`
newParent.style.left = `${left}px`
} catch (err) {
console.error(err)
}

return btnParent
}

Expand Down

0 comments on commit 2a29e37

Please sign in to comment.