Skip to content

Commit ef91608

Browse files
committed
feat(Templates): add search functionality for user templates
1 parent 7344c78 commit ef91608

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/livecodes/html/templates.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
<li>
1111
<a href="#" data-target="templates-user" data-i18n="templates.user.heading">My Templates</a>
1212
</li>
13+
<li class="templates-search">
14+
<label for="templates-search-input" class="visually-hidden" data-i18n="templates.search.label">Search templates</label>
15+
<input id="templates-search-input" type="search" placeholder="Filter languages..." aria-label="Filter templates by language" />
16+
</li>
1317
</ul>
1418

1519
<div id="templates-starter" class="tab-content active">
@@ -28,3 +32,24 @@
2832
</div>
2933
</div>
3034
</div>
35+
36+
<!-- Inline: emit a "templates:filter" event with the current query so other scripts can perform filtering -->
37+
<script>
38+
(function () {
39+
var input = document.getElementById('templates-search-input');
40+
if (!input) return;
41+
42+
var emit = function (value) {
43+
var ev = new CustomEvent('templates:filter', { detail: { query: value } });
44+
document.getElementById('templates-container').dispatchEvent(ev);
45+
};
46+
47+
var timeout = null;
48+
input.addEventListener('input', function (e) {
49+
var val = e.target.value || '';
50+
// debounce to avoid excessive events while typing
51+
clearTimeout(timeout);
52+
timeout = setTimeout(function () { emit(val.trim()); }, 150);
53+
});
54+
})();
55+
</script>

0 commit comments

Comments
 (0)