Skip to content

Commit 3c3868f

Browse files
committed
Fix black key click activating white key in piano UI
This removes CSS :active pseudo-class which propagates to parent elements, causing white keys to highlight when clicking nested black keys. It uses JavaScript-controlled .active class exclusively for key states.
1 parent a557785 commit 3c3868f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

web/app.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,12 @@ function buildKeyboard() {
112112

113113
/* Pointer events for mouse and touch */
114114
kbd.addEventListener('pointerdown', (e) => {
115-
const key = e.target.closest('.key');
115+
const target = e.target;
116+
/* Black keys take priority - check if clicked element is black key */
117+
const blackKey = target.classList.contains('black') ? target : null;
118+
const key = blackKey || target.closest('.key');
116119
if (!key) return;
120+
e.stopPropagation();
117121
kbd.setPointerCapture(e.pointerId);
118122
playNote(parseInt(key.dataset.midi));
119123
});

web/style.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ main {
163163
border-radius: 2px;
164164
}
165165

166-
.key.white.active, .key.white:active {
166+
.key.white.active {
167167
background: var(--primary);
168168
}
169169

170-
.key.black.active, .key.black:active {
170+
.key.black.active {
171171
background: var(--primary);
172172
}
173173

0 commit comments

Comments
 (0)