fix: btn text

This commit is contained in:
Xmader 2020-11-23 15:57:20 -05:00
parent baadfb4e1a
commit 7a53e5d9ca
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
1 changed files with 15 additions and 14 deletions

View File

@ -33,10 +33,7 @@ const buildDownloadBtn = () => {
const textNode = document.createElement('span') const textNode = document.createElement('span')
btn.append(svg, textNode) btn.append(svg, textNode)
return { return btn
btn,
textNode,
}
} }
const cloneBtn = (btn: HTMLButtonElement) => { const cloneBtn = (btn: HTMLButtonElement) => {
@ -67,28 +64,32 @@ export class BtnList {
constructor (private getBtnParent: () => HTMLDivElement = getBtnContainer) { } constructor (private getBtnParent: () => HTMLDivElement = getBtnContainer) { }
add (options: BtnOptions): BtnElement { add (options: BtnOptions): BtnElement {
const { btn, textNode } = buildDownloadBtn() const btnTpl = buildDownloadBtn()
const setText = (str: string): void => { const setText = (btn: BtnElement) => {
textNode.textContent = str const textNode = btn.querySelector('span')
return (str: string): void => {
if (textNode) textNode.textContent = str
}
} }
setText(options.name) setText(btnTpl)(options.name)
btn.onclick = (): void => { btnTpl.onclick = function () {
options.action(options.name, btn, setText) const btn = this as BtnElement
options.action(options.name, btn, setText(btn))
} }
this.list.push(btn) this.list.push(btnTpl)
if (options.disabled) { if (options.disabled) {
btn.disabled = options.disabled btnTpl.disabled = options.disabled
} }
if (options.tooltip) { if (options.tooltip) {
btn.title = options.tooltip btnTpl.title = options.tooltip
} }
return btn return btnTpl
} }
private _commit () { private _commit () {