Skip to content

Commit ac349c6

Browse files
committed
the actual search functionality
1 parent 2112361 commit ac349c6

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ <h1>Honda OBD0/1 ECU Component List</h1>
2828
</header>
2929
<main>
3030
<h2>Components</h2>
31+
<div id="search-container">
32+
<input type="search" id="componentSearch" placeholder="Search components...">
33+
<small>Search by ID, type, specs or notes</small>
34+
</div>
3135
<div id="table-container">
3236
<table>
3337
<thead>

script.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,15 @@ fetch('./hondaecucomponents.json')
8484
credits.appendChild(li);
8585
});
8686
}
87-
}).catch(err => console.error('Failed to load components:', err));
87+
}).catch(err => console.error('Failed to load components:', err));
88+
89+
document.getElementById('componentSearch').addEventListener('input', e => {
90+
const searchTerm = e.target.value.toLowerCase();
91+
const componentGroups = document.getElementsByClassName('component-group');
92+
93+
Array.from(componentGroups).forEach(tbody => {
94+
const searchText = [...Array.from(tbody.querySelector('.component-row').children).map(cell => cell.dataset.original || cell.textContent), tbody.querySelector('.notes-cell')?.textContent || ''].join(' ').toLowerCase();
95+
96+
tbody.style.display = searchText.includes(searchTerm) ? '' : 'none';
97+
});
98+
});

styles.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ th {
8484
position: static;
8585
text-transform: uppercase;
8686
}
87+
88+
#search-container { display: none; }
8789
}
8890

8991
.component-group {
@@ -142,4 +144,24 @@ th {
142144

143145
.honda-link {
144146
color: var(--honda-red);
147+
}
148+
149+
#search-container {
150+
margin: 1rem 0;
151+
}
152+
153+
#componentSearch {
154+
width: 100%;
155+
max-width: 300px;
156+
padding: 0.5rem;
157+
border: 1px solid #d1d5db;
158+
border-radius: 0.25rem;
159+
font-size: 1rem;
160+
}
161+
162+
#search-container small {
163+
display: block;
164+
margin-top: 0.25rem;
165+
color: #4b5563;
166+
font-size: 0.75rem;
145167
}

0 commit comments

Comments
 (0)