Skip to content

Commit e5482ae

Browse files
authored
fix: 🐛 spawn colour picker at pointer location (#223)
1 parent 62469a4 commit e5482ae

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

web/mtb_widgets.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -536,21 +536,34 @@ export const MtbWidgets = {
536536
picker.type = 'color'
537537
picker.value = this.value
538538

539-
picker.style.position = 'absolute'
540-
picker.style.left = '999999px' //(window.innerWidth / 2) + "px";
541-
picker.style.top = '999999px' //(window.innerHeight / 2) + "px";
542-
543-
document.body.appendChild(picker)
539+
Object.assign(picker.style, {
540+
position: "fixed",
541+
left: `${e.clientX}px`,
542+
top: `${e.clientY}px`,
543+
height: "0px",
544+
width: "0px",
545+
padding: "0px",
546+
opacity: 0,
547+
})
544548

545-
picker.addEventListener('change', () => {
546-
this.value = picker.value
549+
picker.addEventListener("blur", () => {
547550
this.callback?.(this.value)
548551
node.graph._version++
549-
node.setDirtyCanvas(true, true)
550552
picker.remove()
551553
})
554+
picker.addEventListener("input", () => {
555+
if (!picker.value) return
556+
557+
this.value = picker.value
558+
app.canvas.setDirty(true)
559+
})
560+
561+
document.body.appendChild(picker)
552562

553-
picker.click()
563+
requestAnimationFrame(() => {
564+
picker.showPicker()
565+
picker.focus()
566+
})
554567
}
555568
}
556569
}

0 commit comments

Comments
 (0)