Fix mode tab buttons: explicit IDs, flex-wrap, z-index

- Add explicit IDs to mode tab buttons (modeImage, modePattern)
- Bind click handlers directly by ID instead of querySelectorAll
- Add type="button" to prevent form submit behavior
- Change controls flex-wrap to wrap (was nowrap, hiding tabs on narrow screens)
- Add user-select: none and z-index to tab buttons
- Dedicated switchMode() function for cleaner state management

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-04-02 02:31:51 +00:00
parent 6a4aa2456f
commit 7dbff3473a
3 changed files with 28 additions and 24 deletions

View File

@ -38,26 +38,26 @@ let currentMode = 'image';
// ── Mode Switching ────────────────────────────── // ── Mode Switching ──────────────────────────────
document.querySelectorAll('.mode-tab').forEach(tab => { const modeImage = $('modeImage');
tab.addEventListener('click', () => { const modePattern = $('modePattern');
document.querySelectorAll('.mode-tab').forEach(t => t.classList.remove('active'));
tab.classList.add('active');
currentMode = tab.dataset.mode;
if (currentMode === 'pattern') { function switchMode(mode) {
imageControls.style.display = 'none'; currentMode = mode;
patternControls.style.display = 'flex'; modeImage.classList.toggle('active', mode === 'image');
generateBtn.style.display = 'none'; modePattern.classList.toggle('active', mode === 'pattern');
randomBtn.style.display = '';
} else { imageControls.style.display = mode === 'image' ? 'flex' : 'none';
imageControls.style.display = 'flex'; patternControls.style.display = mode === 'pattern' ? 'flex' : 'none';
patternControls.style.display = 'none'; generateBtn.style.display = mode === 'image' ? '' : 'none';
generateBtn.style.display = ''; randomBtn.style.display = mode === 'pattern' ? '' : 'none';
generateBtn.disabled = !currentFile;
randomBtn.style.display = 'none'; if (mode === 'image') {
} generateBtn.disabled = !currentFile;
}); }
}); }
modeImage.addEventListener('click', () => switchMode('image'));
modePattern.addEventListener('click', () => switchMode('pattern'));
// ── File Handling ────────────────────────────── // ── File Handling ──────────────────────────────

View File

@ -38,11 +38,11 @@ header {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 10px; gap: 10px;
padding: 6px 12px; padding: 8px 12px;
background: var(--surface); background: var(--surface);
border-bottom: 1px solid var(--border); border-bottom: 1px solid var(--border);
overflow-x: auto; overflow-x: auto;
flex-wrap: nowrap; flex-wrap: wrap;
} }
/* ── Mode Tabs ─────────────────────────────── */ /* ── Mode Tabs ─────────────────────────────── */
@ -68,6 +68,10 @@ header {
transition: all 0.2s; transition: all 0.2s;
white-space: nowrap; white-space: nowrap;
letter-spacing: 0.3px; letter-spacing: 0.3px;
user-select: none;
-webkit-user-select: none;
position: relative;
z-index: 1;
} }
.mode-tab:hover { .mode-tab:hover {

View File

@ -17,9 +17,9 @@
<!-- Controls Bar --> <!-- Controls Bar -->
<div class="controls"> <div class="controls">
<!-- Mode tabs --> <!-- Mode tabs -->
<div class="mode-tabs"> <div class="mode-tabs" id="modeTabs">
<button class="mode-tab active" data-mode="image">&#x1F5BC; Image</button> <button type="button" class="mode-tab active" data-mode="image" id="modeImage">&#x1F5BC; Image</button>
<button class="mode-tab" data-mode="pattern">&#x2728; Patterns</button> <button type="button" class="mode-tab" data-mode="pattern" id="modePattern">&#x2728; Patterns</button>
</div> </div>
<!-- Image mode controls --> <!-- Image mode controls -->