Member directory
A list of person-cards, filtered live by a text field (the library's field) and by track checkboxes, with the filter state in the URL's query so a filtered view is shareable, a count read once by a status region, and a kind empty state that names the two fixes.
quiet warm playful
Open the live demo
npx @susegad/cli add member-directory
Stands on: Checkbox, Core, Core: components, Engine, Field (TextField, TextArea, Select), Person card, Tokens
The prompt
the prompt
Make a member-directory recipe that filters a list of person-card web components by a text field and by track, built from library parts only: the library's <sg-field> for the text input, <sg-check> for the track checkboxes, and <sg-person-card> for each member. The text matches any word against the card's name heading, its role line and its building line (fold accents, so "fernandés" matches "Fernandes"; two words must both match). The track checkboxes narrow to the ticked tracks, and none ticked means every track; the card declares its track with a data-track attribute, and the tracks are: AI for Senior Citizens, AI for Kids, Tech for Good, Builders Moving to Goa, Workshops for Founders. Filtering happens live as the person types. The filter state lives in the URL's query (?q=aldona&track=AI%20for%20Kids), written with history.replaceState so the back button still works, read back into the controls on load, and the page says once that a filtered view is in the address and can be copied. A role="status" count says how many show ("Showing 7 members"). When nothing matches, hide every card and show a kind empty state that names the two fixes: "No one matches that yet. Try a shorter word, or a different track." Without JavaScript the full list shows, unfiltered, the filters do nothing and say so, and nothing breaks.
Words to code
| When you say | Technique | What happens |
|---|---|---|
| what each card says, in data | pure core | personOf(card) reads the card's own markup: the heading, .sg-person-role and .sg-person-building carry the words, data-track the track. |
| fold accents | fold(t) | lowercase and strip diacritics with normalize('NFD'), so the filter forgives them. |
| any word against name, role, building | filterPeople(people, { q, tracks }) | every word you typed must appear somewhere in that person's words; runs in Node, tested without a browser. |
| none ticked means every track | the same core | tracks: [] matches everything; a ticked set keeps only its members. |
| the state lives in the URL | stateOf(params), stateToQuery(state) | read ?q and a comma-joined ?track from the query, and write back with history.replaceState on each change, omitting what is empty. |
| the list updates as you type | wiring | input on the field, change on each checkbox; the element's submit is prevented. |
| the count, read once | role="status" | .sg-directory-count says "Showing 7 members"; a screen reader hears each change once, not per keystroke. |
| the kind empty state | the page's words | .sg-directory-empty unhidden with the two fixes in it; never a blank list. |
| nothing breaks without JavaScript | honesty | No script: the full list shows, the filters do nothing, and a noscript note says so. |
| sample people | markup | Seven made-up people in and around Aldona, one per track or two, each a person-card with a role, what they are building, and a link. No real people or businesses. |
Accessibility
- The field has a real
<label for>; the checkboxes are native inputs. - The count is
role="status": each change is heard once. - Hidden cards are
hidden, so they leave the tab order; the empty state replaces them. - The share note is ordinary text, shown whenever the filter hides anything.
- Without JavaScript nothing is hidden, nothing is broken, and it says why the filters are inert.
A list of <sg-person-card>s, filtered live by a text field and by track, with
the filter state in the address so a filtered view is shareable, and a kind
empty state.
Mount it
<link rel="stylesheet" href="susegad/components/field/field.css">
<link rel="stylesheet" href="susegad/components/check/check.css">
<link rel="stylesheet" href="susegad/components/person-card/person-card.css">
<link rel="stylesheet" href="susegad/recipes/member-directory/recipe.css">
<div class="sg-directory" id="directory">
<form class="sg-directory-filters" action="./">
<sg-field>
<label for="q">Search the members</label>
<input id="q" name="q" type="search" autocomplete="off">
</sg-field>
<fieldset class="sg-directory-tracks">
<legend>Track</legend>
<!-- one sg-check per track; the value is the track's own name -->
<sg-check><label><input type="checkbox" name="track" value="AI for Kids"> AI for Kids</label></sg-check>
</fieldset>
</form>
<p class="sg-directory-count" role="status">Showing 7 members</p>
<ul class="sg-directory-list">
<li><sg-person-card data-track="AI for Kids">…</sg-person-card></li>
</ul>
<div class="sg-directory-empty" hidden>
<p>No one matches that yet. Try a shorter word, or a different track.</p>
</div>
<p class="sg-directory-share" hidden>This filtered view is in the address; copy it and anyone opening it sees the same members.</p>
</div>
<script type="module">
import { mountDirectory } from 'susegad/recipes/member-directory/recipe.js';
await Promise.all(['sg-field', 'sg-check', 'sg-person-card'].map(t => customElements.whenDefined(t)));
mountDirectory(document.getElementById('directory'));
</script>
How it behaves
- The text field matches any word against the name, the role and the building line of each card. Two words must both match. Accents are folded, so "fernandés" finds "Fernandes".
- The track checkboxes narrow to the tracks that are ticked; none ticked
means every track. The card declares its own track with
data-track. - Both together narrow further. The list below updates as you type.
- The address carries the filter:
?q=aldona&track=AI%20for%20Kidsis a complete, shareable view. It is written withhistory.replaceState, so the back button still works, and it is read back on load into the controls. - The empty state is the page's own words, not a blank list: "No one matches that yet. Try a shorter word, or a different track."
- The count is a
role="status"region, so a screen reader hears each change once.
Without JavaScript
The full list shows, unfiltered, and every card reads fine (name, role, work, link). The filters still render but do nothing, and a note inside the form says so plainly. Nothing breaks.
Own the words
The count ("Showing 7 members") and the empty state are written by the recipe's
STRINGS in recipe.js. Change them there, and keep them kind.