Skip to content

Commit 0ca74a1

Browse files
committed
fix(potentiometer): improve knob accuracy
1 parent 7b64379 commit 0ca74a1

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/potentiometer-element.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@ export class PotentiometerElement extends LitElement {
8080
stroke-width=".30"
8181
/>
8282
<rect x="5.4" y=".70" width="9.1" height="1.9" fill="#ccdae3" stroke-width=".15" />
83-
<ellipse cx="9.91" cy="8.18" rx="7.27" ry="7.43" fill="#e4e8eb" stroke-width=".15" />
83+
<ellipse
84+
id="knob"
85+
cx="9.91"
86+
cy="8.18"
87+
rx="7.27"
88+
ry="7.43"
89+
fill="#e4e8eb"
90+
stroke-width=".15"
91+
/>
8492
<rect
8593
x="6.6"
8694
y="17"
@@ -134,12 +142,14 @@ export class PotentiometerElement extends LitElement {
134142
event.stopPropagation();
135143
event.preventDefault();
136144

137-
const potentiometerRect = this.getBoundingClientRect();
145+
const potentiometerRect = this.shadowRoot?.querySelector('#knob')?.getBoundingClientRect();
138146

139-
this.center = {
140-
x: window.scrollX + potentiometerRect.left + potentiometerRect.width / 2,
141-
y: window.scrollY + potentiometerRect.top + potentiometerRect.height / 2,
142-
};
147+
if (potentiometerRect) {
148+
this.center = {
149+
x: window.scrollX + potentiometerRect.left + potentiometerRect.width / 2,
150+
y: window.scrollY + potentiometerRect.top + potentiometerRect.height / 2,
151+
};
152+
}
143153
}
144154

145155
private rotateHandler(event: MouseEvent | TouchEvent) {

0 commit comments

Comments
 (0)