· 3 min read
A tag sidebar for the blog
The first thing on /blog was a wall of 55 unstyled tag links (in dev; 28 of them on a single post). Looked at how others do it: Kent C. Dodds (topic pills…
What we did
- The first thing on
/blogwas a wall of 55 unstyled tag links (in dev; 28 of them on a single post). Looked at how others do it: Kent C. Dodds (topic pills that filter), Josh Comeau (a few categories in a sidebar), Maggie Appleton (a scrolling row), Jim Nielsen (all tags, on their own page). I picked Josh's two columns. /blogis two columns from 60rem: posts, and a "Browse by tag" sidebar. On a phone the sidebar is above the posts. The page setscomposition: 'default'to get out of the blog's narrow reading column.TagCloud.svelte: chips, most used first, each with its own colour (a hue from a hash of the name, the samehueOf()as the generic skill icons, now insrc/lib/hue.ts): a stripe on the edge, an 8% tint, and the/aboutspotlight ring near the pointer (spotlight.ts, moved tosrc/lib/).- Folded, the list shows a few rows (
--tag-rows: 9 beside the posts, 4 on a phone) and fades out into a + button that shows them all. - Each chip reads "#css, 26 posts" to a screen reader (it used to be "#css 26").
- The first post card's cover now loads eagerly with
fetchpriority="high"(apriorityprop onTeaserCard).
What I learned
- Fewer, not prettier: the problem was 55 links, not their style. Sorting by count and folding the long tail fixed more than any styling.
- Faded isn't hidden: a tag under the fade can still get keyboard focus, and a screen reader still reads it. So the faded row and everything below it is
inertuntil the list opens, measured again by aResizeObserverwhenever the list wraps differently. - Fold in the CSS, not from
onMount: the fold is under@media (scripting: enabled)from the start, so the page doesn't jump when the JS arrives; without JS every tag shows and the button is hidden. - After "show all", focus moves to the first tag that was hidden: what I asked to see.
- A tint is a new background: I checked text on every hue (in steps of 3°), every theme, both modes. The worst is 4.81:1.
Problems & fixes
- The + button showed without JS: my
@media (scripting: none)rule came before the button's owndisplay. Same specificity, so the later rule won. Moved it after. - Lighthouse performance on
/blogwent from 96 to 91: on a phone the first post's cover is now above the fold and becomes the LCP (3.3 s simulated; the page's first paint is 2.0 s). Eager loading andfetchpriorityare right for an LCP image but didn't move the simulated number. Accepted for now.
Links
Next
- Maybe: filter the posts in place when a tag is picked (like Kent's), and tidy the tags (
a11yoraccessibility, one-post tags).