Skip to content

Commit

Permalink
Merge pull request #26 from DSACMS/search-box
Browse files Browse the repository at this point in the history
Add search box to projects page.
  • Loading branch information
Gaelan authored Aug 7, 2023
2 parents b3d67df + da24374 commit 367c67f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
19 changes: 17 additions & 2 deletions site/projects.liquid
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
---
layout: base
---
<script type="module" src="/assets/js/projects.js"></script>
<div class="grid-container">
The Centers for Medicare and Medicaid Services develops or funds many open-source projects. Here are some of them:
<p>
The Centers for Medicare and Medicaid Services develops or supports many open-source projects. Here are some of
them:
</p>
<div class="margin-bottom-2">
<label class="usa-label" for="filter-input">Filter</label>
<div class="usa-input-group width-full maxw-none">
<div class="usa-input-prefix" aria-hidden="true">
<svg aria-hidden="true" role="img" focusable="false" class="usa-icon">
<use xlink:href="/assets/img/sprite.svg#search"></use>
</svg>
</div>
<input class="usa-input" id="filter-input" name="filter-input">
</div>
</div>
<ul class="usa-card-group">
{% for repo in repos.repos %}
<li class="usa-card tablet:grid-col-6">
<li class="usa-card project-card tablet:grid-col-6">
<div class="usa-card__container">
<div class="usa-card__header">
<h2 class="usa-card__heading">
Expand Down
9 changes: 9 additions & 0 deletions src/js/projects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const filterBox = document.getElementById("filter-input")
filterBox.addEventListener("input", () => {
const query = filterBox.value.toLowerCase()
document.querySelectorAll(".project-card").forEach((card) => {
card.hidden = !(
query == "" || card.textContent.toLowerCase().includes(query)
)
})
})

0 comments on commit 367c67f

Please sign in to comment.